0

I am trying to use the python speech_recognition to get text from a set of frames in a wave file got from a client.

I have tried to use speech_recognition on a wave object but this doesn't work and it only works on files (or the path to a file)

I tried:

import speech_recognition as sr
import wave

r = sr.Recognizer()

# code to get frames

waveFile = wave.open(file, 'wb')
waveFile.setnchannels(1)
waveFile.setsampwidth(2)
waveFile.setframerate(44100)
waveFile.writeframes(frames) # from client

f = sr.AudioFile(waveFile)
with f as source:
    audio_file = r.record(source)
text = r.recognize_google(audio_data=audio_file, language="en")
print(text)

Then I get the error:

AssertionError: Given audio file must be a filename string or a file-like object

So I am wondering if there is a way to convert a wave object to a normal file-like object.

help-info.de
  • 6,695
  • 16
  • 39
  • 41
A_K
  • 16
  • 2

0 Answers0