Last active
October 24, 2017 23:06
-
-
Save machisuji/e50bcef41b19c5433c24f1142e092d02 to your computer and use it in GitHub Desktop.
Revisions
-
machisuji revised this gist
Oct 24, 2017 . 1 changed file with 0 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,8 +5,6 @@ # @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", @@ -15,8 +13,6 @@ def say(text, language: nil, output: nil, ssml: false) text: text, text_type: ssml ? 'ssml' : 'text' ) end ## -
machisuji created this gist
Oct 24, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ ## # 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) raise aws_not_configured_message unless aws_configured? 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' ) rescue Aws::Polly::Errors::InvalidSsmlException => e nil 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