Last active
October 24, 2017 23:06
-
-
Save machisuji/e50bcef41b19c5433c24f1142e092d02 to your computer and use it in GitHub Desktop.
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
## | |
# Synthesizes audio for the given text. | |
# | |
# @param text [String] The text to synthesize audio for. | |
# @param output [String|IO] (optional) Path to file to write or IO object to stream to. | |
# @return [SynthesizeSpeechOutput] A struct containing `audio_stream` (IO) and `content_type` (String). | |
def say(text, language: nil, output: nil, ssml: false) | |
client.synthesize_speech( | |
response_target: output, | |
output_format: "ogg_vorbis", | |
sample_rate: "22050", | |
voice_id: language_voice_id(language), | |
text: text, | |
text_type: ssml ? 'ssml' : 'text' | |
) | |
end | |
## | |
# Polly client. Configured through the environment variables | |
# AWS_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY | |
def client | |
@client ||= Aws::Polly::Client.new | |
end | |
def language_voice_id(lang) | |
case lang | |
when "de" | |
"Hans" | |
when "ru" | |
"Maxim" | |
when "en" | |
"Brian" | |
else | |
"Brian" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment