python - 需要帮助解码 WAV 文件电子邮件附件
问题描述
我正在将 Google App Engine 用于基础架构,并且我正在尝试解码附加的 .WAV 文件并将其解码为字符串以传递给谷歌云的语音到文本 api。
这是我的代码,我不知道该怎么做。我尝试使用“base64”或“有效负载中的编码属性”进行解码,但我不断收到此错误:“UnicodeDecodeError: 'utf8' codec can't decode byte 0xc6 in position 4: invalid continuation byte”
我用于测试的 .WAV 文件已使用在线 wav 到 base64 解码器正确解码,但由于某种原因,它不适用于此代码。
def receive(self, mail_message):
if hasattr(mail_message, 'attachments'):
file_name = ""
file_contents = ""
for filename, filecontents in mail_message.attachments:
file_name = filename
file_contents = filecontents.payload.decode(filecontents.encoding)
解决方案
filecontents
不需要任何解码:它已经采用正确的格式(编码为)base64
并准备好使用语音到文本 api 进行进一步处理(如评论部分所述)。
推荐阅读
- environment-variables - 为 aws EMR 添加步骤访问 gocd 管道中的环境变量
- ruby-on-rails - ActiveRecord、pgsql:通过多个索引查询多条记录
- c++ - 使用 .mm 文件中的 Objective-C++ 和 C++ 类将 Apple 的 ClassKit 和 swift 类合并到现有应用程序中时出错
- asp.net - ASP.NET MVC 5 加载时间非常慢
- swift - 为什么 Swift 不解决“索引越界”异常?
- azure - 将文件备份到 Azure 存储
- python - 如何在 ScrapingHub 上将 geckodriver“添加”到 PATH?
- android - 操作栏在 Android Studio 中不可见
- linux - 包含当前目录变量的 Bash 别名
- angular - REST API 以及 Angular6 中的 Admin Web 应用程序