0

"OSError: No Default Input Device Available" on Google Colab

from the above link, I get the record() function and it is great for reading audio in binary form, but due SpeechRecognition library allowing just (PCM WAV, AIFF/AIFF-C, or Native FLAC) I tried to save the binary as WAV file by add to function:

with open('/content/gtx.wav','wb') as f:
   f.write(b)

then all is well, and I found real sound in my drive, but an error appears when trying:

import speech_recognition as sr
r = sr.Recognizer()
temp_voice = sr.AudioFile('/content/gtx.wav')
with temp_voice as file:
   audio = r.record(file)
textout=r.recognize_google(audio)
print(textout)

Error:

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

So how can I read the audio and directly send it to the SpeechRecognition library? Many thanks for every answer.

  • The file may have the .wav extension but it is not a wav apparently. You could either use something like `sox` to convert it to wav before reading it with `speech_recognition`. – geoph9 Feb 01 '22 at 16:31
  • firstly, thanks for your answer I found that the recorded audio in the WAV file is working when playing it on any audio player, I think there is a problem in the "PCM" type of that WAV, could you tell me more about `sox` is it an audio library? could it convert binary one to suitable WAV, I actually do not need all of that, I just want to read from Mic. to `speech_recognition` if that is possible. thanks again – Hasanen A. Sahib Feb 03 '22 at 21:59
  • Wav files are just a way to store PCM data. Standard players usually first get the type of the audio before playing it (so your audio may be some other type that your player is able to play but `speech_recognition` is not). `sox` has many audio manipulation helpers and is used a lot in audio processing. You could download it and first check `soxi – geoph9 Feb 04 '22 at 06:03
  • well I will try it, many thanks – Hasanen A. Sahib Feb 05 '22 at 11:28

0 Answers0