[英]Returning an audio file as response from AWS Lambda function
I have an AWS API Gateway calling a Lambda function (with Proxy integration), which should return an audio file.我有一个 AWS API 网关调用 Lambda function(代理集成),它应该返回一个音频文件。
Let's say that I have my audio as 'bytes' object. How do I go about returning it, such that it can immediately be recognized and played by the browser (eg Firefox)?假设我的音频为“字节”object。如何返回它 go,以便它可以立即被浏览器(例如 Firefox)识别和播放?
Here's what I got, but, clearly, that doesn't really work.这就是我得到的,但是,显然,这并没有真正起作用。
sound: bytes
return {
'statusCode': 200,
'headers': {
'Content-Type': 'audio/mpeg'
},
'isBase64Encoded': True,
'body': base64.b64encode(sound)
}
base64.b64encode(sound)
in Python) and put the result in 'body'
of your response dictionary. base64.b64encode(sound)
)并将结果放入响应字典的'body'
中。'isBase64Encoded'
to true in your response dictionary.'isBase64Encoded'
设置为true 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.