Last active
March 13, 2019 07:25
-
-
Save mludvig/f5127c4bf7c809e69c51c5b73c75f14c to your computer and use it in GitHub Desktop.
Sample code for using AWS Polly in Python
This file contains 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
#!/usr/bin/env python3 | |
# audio_helper.py - simple PyGame audio player | |
# Author Michael Ludvig | |
import io | |
import pygame | |
# PyGame initialisation - upon module loading | |
pygame.init() | |
pygame.mixer.init() | |
# Convert boto3 audio stream to Bytes stream | |
# for compatibility with pygame | |
def play_audio_stream(audio_stream): | |
audio = io.BytesIO(audio_stream.read()) | |
play_audio(audio) | |
# Here we play the audio stream | |
def play_audio(audio): | |
pygame.mixer.music.load(audio) | |
pygame.mixer.music.play() | |
while pygame.mixer.music.get_busy(): | |
pygame.time.Clock().tick(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment