我有像data:audio/mpeg;base64,//OAxAAAAANIAAAAABhqZ3f4StN3gOAaB4NAUBYZLv......这样的base64音频字符串,我试图使用Python中的base64模块将base64转换为wav文件:
decode_bytes = base64.b64decode(encoding_str)
with open(file_name + '.wav', "wb") as wav_file:
wav_file.write(decode_bytes)然后我尝试使用speech_recognition模块将音频转换为文本,错误如下:
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这个问题有解决方案吗?
发布于 2020-06-26 15:09:44
你的音频文件似乎是来自mime- mp3 - audio/mpeg的类型。您需要将其另存为mp3
decode_bytes = base64.b64decode(encoding_str)
with open(file_name + '.mp3', "wb") as wav_file:
wav_file.write(decode_bytes)并使用pydub或FFmpeg将mp3转换为wav格式,然后将此wav文件提供给speech_recognition模块。
https://stackoverflow.com/questions/62587308
复制相似问题