我正在尝试使用python speech_recognition
从客户机获取的wave
文件中的一组帧获取文本
我试过在speech_recognition
对象上使用wave
,但这不起作用,它只在文件(或文件路径)上起作用
我试过:
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)
然后我得到一个错误:
AssertionError: Given audio file must be a filename string or a file-like object
所以我想知道是否有一种方法可以将wave对象转换成普通的文件状对象
目前没有回答
相关问题 更多 >
编程相关推荐