espeak-ruby-1.0.5/0000755000004100000410000000000014153406571014002 5ustar www-datawww-dataespeak-ruby-1.0.5/test/0000755000004100000410000000000014153406571014761 5ustar www-datawww-dataespeak-ruby-1.0.5/test/cases/0000755000004100000410000000000014153406571016057 5ustar www-datawww-dataespeak-ruby-1.0.5/test/cases/voice_test.rb0000644000004100000410000000055714153406571020557 0ustar www-datawww-data# frozen_string_literal: true require 'test_helper' class VoiceTest < Test::Unit::TestCase include ESpeak def test_all all_voices = Voice.all assert all_voices.size.positive? assert %w[M F].include?(all_voices.first.gender) end def test_find_by_language voice = Voice.find_by_language('en') assert_equal 'en', voice.language end end espeak-ruby-1.0.5/test/cases/speech_test.rb0000644000004100000410000000060014153406571020706 0ustar www-datawww-data# frozen_string_literal: true require 'test_helper' require 'fileutils' class SpeechTest < Test::Unit::TestCase include ESpeak def test_save FileUtils.rm_rf('test/tmp') FileUtils.mkdir_p('test/tmp') assert Speech.new('Hello!').save('test/tmp/test.mp3') assert File.exist?('test/tmp/test.mp3'), 'Mp3 file not generated' FileUtils.rm_rf('test/tmp') end end espeak-ruby-1.0.5/test/test_helper.rb0000644000004100000410000000012714153406571017624 0ustar www-datawww-data# frozen_string_literal: true require 'rubygems' require 'test/unit' require 'espeak' espeak-ruby-1.0.5/README.md0000644000004100000410000000401214153406571015256 0ustar www-datawww-data# espeak-ruby espeak-ruby is a small Ruby API for utilizing [espeak](http://espeak.sourceforge.net) and [lame](http://lame.sourceforge.net/) to create Text-To-Speech mp3 files. It can also just speak (without saving). ## Install Add _espeak-ruby_ to Gemfile ```ruby gem "espeak-ruby", require: "espeak" ``` ## Examples ```ruby # Speaks "YO!" speech = ESpeak::Speech.new("YO!") speech.speak # invokes espeak # Creates hello-de.mp3 file speech = ESpeak::Speech.new("Hallo Welt", voice: "de") speech.save("hello-de.mp3") # invokes espeak + lame # Lists voices ESpeak::Voice.all.map { |v| v.language } # ["af", "bs", "ca", "cs", "cy", "da", "de", "el", "en", "en-sc", "en-uk", "en-uk-north", "en-uk-rp", "en-uk-wmids", "en-us", "en-wi", "eo", "es", "es-la", "fi", "fr", "fr-be", "grc", "hi", "hr", "hu", "hy", "hy", "id", "is", "it", "jbo", "ka", "kn", "ku", "la", "lv", "mk", "ml", "nci", "nl", "no", "pap", "pl", "pt", "pt-pt", "ro", "ru", "sk", "sq", "sr", "sv", "sw", "ta", "tr", "vi", "zh", "zh-yue"] # Find particular voice ESpeak::Voice.find_by_language('en') # ``` ## Features Currently only subset of espeak features is supported. ```ruby :voice => 'en' # use voice file of this name from espeak-data/voices :pitch => 50 # pitch adjustment, 0 to 99 :speed => 170 # speed in words per minute, 80 to 370 :capital => 170 # increase emphasis (pitch) of capitalized words, 1 to 40 (for natural sound, can go higher) ``` These are default values, and they can be easily overridden: ```ruby Speech.new("Zdravo svete", voice: "sr", pitch: 90, speed: 200).speak ``` ## Installing dependencies ### OS X brew install espeak lame ### Ubuntu apt-get install espeak lame ## Related * [espeak-http](http://github.com/dejan/espeak-http) - Micro web app for Text-To-Speech conversion via HTTP powered by Ruby, Sinatra, lame, espeak and espeak-ruby ## Licence espeak-ruby is released under the [MIT License](/MIT-LICENSE). espeak-ruby-1.0.5/Rakefile0000644000004100000410000000045014153406571015446 0ustar www-datawww-data# frozen_string_literal: true require 'rake/testtask' require 'rubocop/rake_task' desc 'Default: run tests' task default: :test desc 'Test espeak-ruby' Rake::TestTask.new(test: :rubocop) do |t| t.libs << 'test' t.pattern = 'test/**/*_test.rb' t.verbose = true end RuboCop::RakeTask.new espeak-ruby-1.0.5/lib/0000755000004100000410000000000014153406571014550 5ustar www-datawww-dataespeak-ruby-1.0.5/lib/espeak/0000755000004100000410000000000014153406571016020 5ustar www-datawww-dataespeak-ruby-1.0.5/lib/espeak/speech.rb0000644000004100000410000000476114153406571017624 0ustar www-datawww-data# frozen_string_literal: true module ESpeak # Speech represents an Text-To-Speech audio that can be played or saved to file class Speech attr_reader :options, :text # filename - The file that will be generated # options - Posible key, values # :voice - use voice file of this name from espeak-data/voices. ie 'en', 'de', ... # :pitch - pitch adjustment, 0 to 99 # :speed - speed in words per minute, 80 to 370 # :capital - increase emphasis of capitalized letters by raising pitch by this amount # no range given in man but good range is 10-40 to start # :quiet - remove printing to stdout. Affects only lame (default false) # def initialize(text, options = {}) @text = text @options = options end # Speaks text # def speak IO.popen(espeak_command(command_options), 'r', &:read) end # Generates mp3 file as a result of # Text-To-Speech conversion. # def save(filename) speech = bytes_wav res = IO.popen(lame_command(filename, command_options), 'r+') do |process| process.write(speech) process.close_write process.read end res.to_s end # Returns mp3 file bytes as a result of # Text-To-Speech conversion. # def bytes speech = bytes_wav res = IO.popen(std_lame_command(command_options), 'r+') do |process| process.write(speech) process.close_write process.read end res.to_s end # Returns wav file bytes as a result of # Text-To-Speech conversion. # def bytes_wav IO.popen(espeak_command(command_options, '--stdout'), 'r', &:read) end private def command_options default_options.merge(options.transform_keys(&:to_sym)) end # Although espeak itself has default options # I'm defining them here for easier generating # command (with simple hash.merge) # def default_options { voice: 'en', pitch: 50, speed: 170, capital: 1, quiet: true } end def espeak_command(options, flags = '') ['espeak', @text.to_s, flags.to_s, "-v#{options[:voice]}", "-p#{options[:pitch]}", "-k#{options[:capital]}", "-s#{options[:speed]}"] end def std_lame_command(options) lame_command('-', options) end def lame_command(filename, options) ['lame', '-V2', '-', filename.to_s, ('--quiet' if options[:quiet] == true).to_s] end end end espeak-ruby-1.0.5/lib/espeak/voice.rb0000644000004100000410000000140014153406571017445 0ustar www-datawww-data# frozen_string_literal: true module ESpeak # A voice that will be used for `Speech` class Voice attr_reader :language, :name, :gender, :file def initialize(attributes) @language = attributes[:language] @name = attributes[:name] @gender = attributes[:gender] @file = attributes[:file] end def self.all voices = [] result = IO.popen('espeak --voices', &:read) result.each_line do |line| next unless line.start_with?(' ') # header row = line.split voices << Voice.new(language: row[1], gender: row[2], name: row[3], file: row[4]) end voices.freeze end def self.find_by_language(lang) all.find { |v| v.language == lang.to_s } end end end espeak-ruby-1.0.5/lib/espeak.rb0000644000004100000410000000021314153406571016341 0ustar www-datawww-data# frozen_string_literal: true module ESpeak autoload :Speech, 'espeak/speech' autoload :Voice, 'espeak/voice' end ESpeak::Voice.all espeak-ruby-1.0.5/espeak-ruby.gemspec0000644000004100000410000000406014153406571017576 0ustar www-datawww-data######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- # stub: espeak-ruby 1.0.5 ruby lib Gem::Specification.new do |s| s.name = "espeak-ruby".freeze s.version = "1.0.5" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.metadata = { "rubygems_mfa_required" => "true" } if s.respond_to? :metadata= s.require_paths = ["lib".freeze] s.authors = ["Dejan Simic".freeze] s.date = "2021-11-30" s.description = "espeak-ruby is small Ruby API for utilizing \u2018espeak\u2019 and \u2018lame\u2019 to create Text-To-Speech mp3 files".freeze s.email = "desimic@gmail.com".freeze s.files = ["README.md".freeze, "Rakefile".freeze, "lib/espeak.rb".freeze, "lib/espeak/speech.rb".freeze, "lib/espeak/voice.rb".freeze, "test/cases/speech_test.rb".freeze, "test/cases/voice_test.rb".freeze, "test/test_helper.rb".freeze] s.homepage = "https://github.com/dejan/espeak-ruby".freeze s.licenses = ["MIT".freeze] s.required_ruby_version = Gem::Requirement.new(">= 2.5.0".freeze) s.rubygems_version = "2.7.6.2".freeze s.summary = "espeak-ruby is small Ruby API for utilizing \u2018espeak\u2019 and \u2018lame\u2019 to create Text-To-Speech mp3 files".freeze if s.respond_to? :specification_version then s.specification_version = 4 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_development_dependency(%q.freeze, ["~> 13.0.6"]) s.add_development_dependency(%q.freeze, ["~> 1.23"]) s.add_development_dependency(%q.freeze, ["~> 3.5"]) else s.add_dependency(%q.freeze, ["~> 13.0.6"]) s.add_dependency(%q.freeze, ["~> 1.23"]) s.add_dependency(%q.freeze, ["~> 3.5"]) end else s.add_dependency(%q.freeze, ["~> 13.0.6"]) s.add_dependency(%q.freeze, ["~> 1.23"]) s.add_dependency(%q.freeze, ["~> 3.5"]) end end