首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >base64 :如何使用speech_recognition或其他模块将Python音频字符串转换为文本?

base64 :如何使用speech_recognition或其他模块将Python音频字符串转换为文本?
EN

Stack Overflow用户
提问于 2020-06-26 10:53:28
回答 1查看 316关注 0票数 0

我有像data:audio/mpeg;base64,//OAxAAAAANIAAAAABhqZ3f4StN3gOAaB4NAUBYZLv......这样的base64音频字符串,我试图使用Python中的base64模块将base64转换为wav文件:

代码语言:javascript
复制
    decode_bytes = base64.b64decode(encoding_str)
    with open(file_name + '.wav', "wb") as wav_file:
        wav_file.write(decode_bytes)

然后我尝试使用speech_recognition模块将音频转换为文本,错误如下:

代码语言:javascript
复制
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

这个问题有解决方案吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-26 15:09:44

你的音频文件似乎是来自mime- mp3 - audio/mpeg的类型。您需要将其另存为mp3

代码语言:javascript
复制
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模块。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62587308

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档