pax_global_header00006660000000000000000000000064134375137720014526gustar00rootroot0000000000000052 comment=3bd0bb2ea756ec341eb6b55df9ca42cac458c629 ruby-espeak-1.0.4/000077500000000000000000000000001343751377200137575ustar00rootroot00000000000000ruby-espeak-1.0.4/.gitignore000066400000000000000000000000301343751377200157400ustar00rootroot00000000000000TODO Gemfile.lock *.gem ruby-espeak-1.0.4/CHANGELOG000066400000000000000000000006321343751377200151720ustar00rootroot00000000000000## v1.0.3, May 14, 2016 * Remove `sanitized_text` method and use `IO.popen` rather than `system` to prevent command injection. by @bcoles * Add support for -k flag to modulate pitch on capital letter words. by @structuralartistry ## v1.0.2, Feb 24, 2014 * ? ## v1.0.1, Jan 16, 2014 * introduced ESpeak::Voice ## v1.0.0, Jan 12, 2014 * initial stable release ## v0.3.0, Feb 21, 2009 * initial version ruby-espeak-1.0.4/Gemfile000066400000000000000000000001561343751377200152540ustar00rootroot00000000000000source 'http://rubygems.org' gemspec group :development do gem 'rake' gem 'mocha' gem 'test-unit' end ruby-espeak-1.0.4/README.md000066400000000000000000000062051343751377200152410ustar00rootroot00000000000000espeak-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). See the [live demo](http://rors.org/demos/espeak-ruby). Install ------- Add _espeak-ruby_ to Gemfile ```ruby gem "espeak-ruby", require: "espeak" ``` Examples -------- First you need to include ESpeak module to access espeak API ```ruby include ESpeak ``` Then use it like this: ```ruby # Speaks "YO!" speech = Speech.new("YO!") speech.speak # invokes espeak # Creates hello-de.mp3 file speech = Speech.new("Hallo Welt", voice: "de") speech.save("hello-de.mp3") # invokes espeak + lame # Lists voices 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 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 ``` Requirements ------------ * * 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 ------- Copyright (c) 2008 Dejan Simic Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ruby-espeak-1.0.4/Rakefile000066400000000000000000000003211343751377200154200ustar00rootroot00000000000000require 'rake/testtask' desc 'Default: run tests' task :default => :test desc 'Test espeak-ruby' Rake::TestTask.new(:test) do |t| t.libs << "test" t.pattern = 'test/**/*_test.rb' t.verbose = true end ruby-espeak-1.0.4/espeak-ruby.gemspec000066400000000000000000000012551343751377200175560ustar00rootroot00000000000000Gem::Specification.new do |gem| gem.name = 'espeak-ruby' gem.version = '1.0.4' gem.summary = "espeak-ruby is small Ruby API for utilizing ‘espeak’ and ‘lame’ to create Text-To-Speech mp3 files" gem.description = "espeak-ruby is small Ruby API for utilizing ‘espeak’ and ‘lame’ to create Text-To-Speech mp3 files" gem.author = 'Dejan Simic' gem.email = 'desimic@gmail.com' gem.homepage = 'https://github.com/dejan/espeak-ruby' gem.license = 'MIT' # ensure the gem is built out of versioned files gem.files = Dir['Rakefile', '{bin,lib,man,test,spec}/**/*', 'README*', 'LICENSE'] & `git ls-files -z`.split("\0") end ruby-espeak-1.0.4/lib/000077500000000000000000000000001343751377200145255ustar00rootroot00000000000000ruby-espeak-1.0.4/lib/espeak.rb000066400000000000000000000001311343751377200163150ustar00rootroot00000000000000module ESpeak autoload :Speech, 'espeak/speech' autoload :Voice, 'espeak/voice' end ruby-espeak-1.0.4/lib/espeak/000077500000000000000000000000001343751377200157755ustar00rootroot00000000000000ruby-espeak-1.0.4/lib/espeak/speech.rb000066400000000000000000000051561343751377200176000ustar00rootroot00000000000000module ESpeak 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') do |process| process.read end 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') do |process| process.read end end private def command_options default_options.merge(symbolize_keys(options)) 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}", "#{flags}", "-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}", "#{'--quiet' if options[:quiet] == true}"] end def symbolize_keys(hash) hash.inject({}) do |options, (key, value)| options[(key.to_sym rescue key) || key] = value options end end end end ruby-espeak-1.0.4/lib/espeak/voice.rb000066400000000000000000000012441343751377200174300ustar00rootroot00000000000000require 'csv' module ESpeak 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 = [] CSV.parse(espeak_voices, headers: :first_row, col_sep: ' ') do |row| voices << Voice.new(language: row[1], gender: row[2], name: row[3], file: row[4] ) end voices end def self.find_by_language(lang) all.find { |v| v.language == lang.to_s } end def self.espeak_voices `espeak --voices` end end end ruby-espeak-1.0.4/test/000077500000000000000000000000001343751377200147365ustar00rootroot00000000000000ruby-espeak-1.0.4/test/cases/000077500000000000000000000000001343751377200160345ustar00rootroot00000000000000ruby-espeak-1.0.4/test/cases/speech_test.rb000066400000000000000000000005421343751377200206700ustar00rootroot00000000000000require '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 ruby-espeak-1.0.4/test/cases/voice_test.rb000066400000000000000000000007141343751377200205270ustar00rootroot00000000000000require "test_helper" class VoiceTest < Test::Unit::TestCase include ESpeak def setup voices_file = File.read("test/fixtures/voices.txt") Voice.expects(:espeak_voices).returns(voices_file) end def test_all all_voices = Voice.all assert all_voices.size > 0 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 ruby-espeak-1.0.4/test/fixtures/000077500000000000000000000000001343751377200166075ustar00rootroot00000000000000ruby-espeak-1.0.4/test/fixtures/voices.txt000066400000000000000000000062541343751377200206470ustar00rootroot00000000000000Pty Language Age/Gender VoiceName File Other Langs 5 af M afrikaans af 5 bs M bosnian bs 5 ca M catalan ca 5 cs M czech cs 5 cy M welsh-test cy 5 da M danish da 5 de M german de 5 el M greek el 5 en M default default 5 en-sc M en-scottish en/en-sc (en 4) 2 en-uk M english en/en (en 2) 5 en-uk-north M lancashire en/en-n (en-uk 3) 5 en-uk-rp M english_rp en/en-rp (en-uk 4) 5 en-uk-wmids M english_wmids en/en-wm 2 en-us M english-us en/en-us (en-r 5)(en 3) 5 en-wi M en-westindies en/en-wi (en-uk 4) 5 eo M esperanto eo 5 es M spanish es 5 es-la M spanish-latin-american es-la (es-mx 6) 5 fi M finnish fi 5 fr M french fr 5 fr-be M french (Belgium) fr-be 5 grc M greek-ancient test/grc 5 hi M hindi-test hi 5 hr M croatian hr (hbs 5) 5 hu M hungarian hu 5 hy M armenian hy 5 hy M armenian-west hy-west 5 id M indonesian-test id 5 is M icelandic-test is 5 it M italian it 5 jbo lojban test/jbo 5 ka georgian-test ka 5 kn kannada kn 5 ku M kurdish ku 5 la M latin la 5 lv M latvian lv 5 mk M macedonian-test mk 5 ml M malayalam ml 5 nci M nahuatl - classical test/nci 5 nl M dutch-test nl 5 no M norwegian no (nb 5) 5 pap papiamento-test test/pap 5 pl M polish pl 5 pt M brazil pt (pt-br 5) 5 pt-pt M portugal pt-pt 5 ro M romanian ro 5 ru M russian_test ru 5 sk M slovak sk 5 sq M albanian sq 5 sr M serbian sr 5 sv M swedish sv 5 sw M swahihi-test sw 5 ta M tamil ta 5 tr M turkish tr 5 vi M vietnam vi 5 zh M Mandarin zh 5 zh-yue M cantonese zh-yue (yue 5)(zhy 5) ruby-espeak-1.0.4/test/test_helper.rb000066400000000000000000000001161343751377200175770ustar00rootroot00000000000000require 'rubygems' require 'test/unit' require 'mocha/setup' require 'espeak'