Created
May 5, 2020 07:09
-
-
Save lekansogunle/60127ac38f7644ce8eab5a27dea49a53 to your computer and use it in GitHub Desktop.
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
require 'aws-sdk-polly' | |
class TextToSpeech | |
attr_reader :contents, :polly | |
def self.convert(contents) | |
new(contents).convert | |
end | |
def initialize(contents) | |
@polly = Aws::Polly::Client.new | |
@contents = contents | |
end | |
def convert | |
resp = polly.synthesize_speech({ | |
output_format: "mp3", | |
text: contents, | |
voice_id: "Joanna", | |
}) | |
IO.copy_stream(resp.audio_stream, 'speech_content.mp3') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment