I am working on a audioplayer that uses qr-codes as input. it works until it actually needs to play the audio.wav. Then i get the error "UNknown Wave Format".
import cv2
from pytube import YouTube
import pygame
PURPLE = '255, 0, 188'
PATH = 'A:\\VS\\programms\\ai-help'
MUSIC_PATH = 'A:\\VS\\programms\\ai-help\\audio.wav'
link = ''
pygame.mixer.pre_init(44100, 16, 2, 4096) #frequency, size, channels, buffersize
pygame.init()
cap = cv2.VideoCapture(2)
detector = cv2.QRCodeDetector()
def download():
try:
yt = YouTube(link)
except:
print('Connection error')
try:
mp3_stream = yt.streams.filter(only_audio=True).first()
mp3_stream.download(output_path=PATH,filename='audio.wav')
print('download complete')
except:
print('error downloading audiofile')
def play():
pygame.mixer.music.load(MUSIC_PATH)
pygame.mixer.music.play(MUSIC_PATH)
print('now playing')
I already tried using mp3 and changing the sample_frequency and the bitrate, but i cant get it to work.
The file you download is not a
wavormp3file. Since you download it from youtube, I guess it's either anmp4aoropusfile.Since pygame does not support these codecs, you'll have to first convert the file to a supported format.
Here's a simple, working example using ffmpeg and ffmpeg-python: