Skip to content

Instantly share code, notes, and snippets.

@frivas
Last active May 2, 2019 16:08
Show Gist options
  • Save frivas/d7a8a44ebbbb519346893a1ea43dc17c to your computer and use it in GitHub Desktop.
Save frivas/d7a8a44ebbbb519346893a1ea43dc17c to your computer and use it in GitHub Desktop.
Mixing Polly with Audip Clip
def generatePollyMix(polly, text, voice, backgroundSFX, format='mp3'):
resp = polly.synthesize_speech(OutputFormat=format, Text=text, VoiceId=voice)
soundfile = open(f"/tmp/sound.mp3", 'wb')
soundBytes = resp['AudioStream'].read()
soundfile.write(soundBytes)
soundfile.close()
audio = MP3("/tmp/sound.mp3")
audio_length = audio.info.length
sox_cmd = f"/tmp/sox -m {backgroundSFX} /tmp/sound.mp3 -C 48.01 /tmp/output.mp3 rate 22050 gain -l 16 trim 0 {audio_length + 4}"
sox_cmd_output = subprocess.run([sox_cmd], shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
return sox_cmd_output.returncode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment