需要帮助解码WAV文件的电子邮件附件

时间:2019-05-18 11:22:07

标签: python google-app-engine decode wav google-app-engine-python

我正在将Google App Engine用于基础架构,并且尝试解码附加的.WAV文件并将其解码为字符串,以传递到Google Cloud的语音文本API。

这是我的代码,我不知所措。我尝试使用'base64'或“有效负载中的编码属性”进行解码,但我不断收到此错误:“ UnicodeDecodeError:'utf8'编解码器无法解码位置4的字节0xc6:无效的连续字节”

我使用在线WAV到base64解码器正确解码了用于测试的.WAV文件,但由于某些原因,该文件不适用于此代码。

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)

1 个答案:

答案 0 :(得分:2)

filecontents不需要任何解码:它已经采用了正确的格式(编码为base64),并准备通过语音文本api进行进一步处理(如评论部分所述)

相关问题