Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save python1981/25cb7c462e5d96b5ad9257c476a24b0f to your computer and use it in GitHub Desktop.
Save python1981/25cb7c462e5d96b5ad9257c476a24b0f to your computer and use it in GitHub Desktop.
Save Alexa response to ogg audio file
# Manual steps initially:
# 1. Use the Alexa developer console "Test" mode to test your phrase
# 2. View NETWORK DEBUG panel, find the "getTTS" POST request, right-click and "Save as HAR with content" to a file called 'get_tts.txt'
# 3. Run the code below to convert to audio file 'audio.ogg'
import urllib
import json
import base64
with open('tts.txt','r') as f:
tts_raw = f.read()
tts_unquoted = urllib.unquote(tts_raw)
tts_object = json.loads(tts_unquoted)
fh = open("audio.ogg", "wb")
fh.write(tts_object['audioFiles'][0].decode('base64'))
fh.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment