'Speech Recognition: transcribing text "UnknownValueError: "

I'm very new and I apologize in advance if I miss some pieces of information.

I'm transcribing file.wav into strings.

I'm using speech_recognition as sr and r = sr.Recognizer(). I've created a list of directories where files .wav are. The list name is "list_audio_dir". The result is something like this:

['/Users/thatsme/Desktop/Progetto/audio wav/00004065-AUDIO-2021-04-26-14-38-37.wav', ...]

I've used from pathlib import Path to do the above information.

The objective is to create a loop that goes through all the files and converts them into a string, each string (that contains the entire text of the message) goes into the list named "list_text". The code where I'm struggling with is this:

list_text = []
for i in range(0, len(list_audio_dir)):
    str_path = str(list_audio_dir[i:i+1])[2:-2]
    path = Path(str_path)
    with sr.AudioFile(str(path)) as source:
        audio_data = r.record(source)
        text = r.recognize_google(audio_data, language="it-IT")
        list_text.append(text)

Error:

UnknownValueError: 

If instead of for i in range(0, len(list_audio_dir)): I write for i in range(0, 5): I get the result of a list of 5 elements containing the transcription of 5 audio files. Should I do it in chunks?

Thank you



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source