我需要从麦克风录制音频并将其转换为文本。我已经使用从网上下载的几个音频剪辑尝试了这个转换过程,它工作正常。但是,当我尝试转换从麦克风录制的音频剪辑时,会出现以下错误。
回溯(最近一次调用):文件“C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\site-packages\speech_recognition__init__.py”,第 203 行,在输入 self.audio_reader = wave.open (self.filename_or_fileobject, "rb") File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\wave.py", line 510, in open return Wave_read(f) File "C:\ Users\HP\AppData\Local\Programs\Python\Python37\lib\wave.py”,第 164 行,在init self.initfp(f) 文件“C:\Users\HP\AppData\Local\Programs\Python\Python37 \lib\wave.py”,第 144 行,在 initfp self._read_fmt_chunk(chunk) 文件“C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\wave.py”,第 269 行,在 _read_fmt_chunk引发错误('未知格式:%r'%(wFormatTag,)) 波。错误:未知格式:3
我正在尝试的代码如下。
import speech_recognition as sr
import sounddevice as sd
from scipy.io.wavfile import write
# recording from the microphone
fs = 44100 # Sample rate
seconds = 3 # Duration of recording
myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=2)
sd.wait() # Wait until recording is …Run Code Online (Sandbox Code Playgroud)