speech_recognition видит файл формата wav, но не извлекает из него речь

r=sr.Recognizer()

os.chdir(r'U:\FileTXTListFullmp3\randwav')
listwavfiles=os.listdir(r'U:\FileTXTListFullmp3\randwav')
storagewave=r'U:\FileTXTListFullmp3\randwav'

for engwavfile in listwavfiles:  #engwavfile имя файла
    print(engwavfile)
    engwav=sr.AudioFile('But he kept his expression blank.... .wav')#
# engwav = sr.AudioFile(engwavfile)#
    with engwav as source:
        audio=r.record(source)
        engstt = r.recognize_google(audio_data=audio, language='en-US')
      # engwavfile=engwavfile.replace('.wav','')
        engsttsent=open(engwavfile+'txt','w',encoding='utf-8')
        engsttsent.write(engstt)
        engsttsent.close()

вот такую ошибку выдает PyCharm raise ValueError("Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another format") ValueError: Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another format

тоже самое будет если делать как в документации. 1 пример кода, без перебора файлов циклом, брал из видео урока. Там такой ошибки не выдавало

for engwavfile in listwavfiles:

    AUDIO_FILE = path.join(storagewave,'“Based, I am told, on your recommendation, Admiral.... .wav ')

    r = sr.Recognizer()
    with sr.AudioFile(AUDIO_FILE) as source:
        audio = r.record(source)  # read the entire audio file

        # recognize speech using Google Speech Recognition
        try:
            # for testing purposes, we're just using the default API key
            # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
            # instead of `r.recognize_google(audio)`
            a=r.recognize_google(audio, language='en-US')  #a=r.recognize_google(audio, language='ko-Ko')
            print("Google Speech Recognition thinks you said " + a)
        except sr.UnknownValueError:
            print("Google Speech Recognition could not understand audio")
        except sr.RequestError as e:
            print("Could not request results from Google Speech Recognition service; {0}".format(e))

Ответы (0 шт):