Last active
May 2, 2019 16:08
-
-
Save frivas/d7a8a44ebbbb519346893a1ea43dc17c to your computer and use it in GitHub Desktop.
Mixing Polly with Audip Clip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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