Skip to content

Instantly share code, notes, and snippets.

@lekansogunle
Created May 5, 2020 07:09
Show Gist options
  • Save lekansogunle/60127ac38f7644ce8eab5a27dea49a53 to your computer and use it in GitHub Desktop.
Save lekansogunle/60127ac38f7644ce8eab5a27dea49a53 to your computer and use it in GitHub Desktop.
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