以下代码当前将文件保存到磁盘。我可以将其保存到内存中吗?
def synthesize(iam_token, text):
url = 'https://example.com/tts:synthesize'
headers = {
'Authorization': 'Bearer ' + iam_token,
}
data = {
'text': text
}
with requests.post(url, headers=headers, data=data, stream=True) as resp:
for chunk in resp.iter_content(chunk_size=None):
yield chunk
with open('/tmp/tts.ogg', 'wb') as f:
for audio_content in synthesize(iam_token, text):
f.write(audio_content)