espeak-ruby 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 180cad066c032c06a849a41fc576ec2c92e7467a
4
- data.tar.gz: 5a246834822ad4abd75c9b270ebd760e3330b263
3
+ metadata.gz: a8a84ef69d4f7376739a28bce0ab2395dfd9326d
4
+ data.tar.gz: a17f27305b06bfd175057ba77b3d2412af1137f5
5
5
  SHA512:
6
- metadata.gz: 5d1fce395e5c3a91c84f4a6103f2582ade114792d21cff4128d237b3d07c7c98553b876c6eff0f88f024a877412fe5c1ec9f19a3bd35910318a2713b86f20e34
7
- data.tar.gz: 00f1b281b7f5f5aa7851ecd98714136140a5541fe2d94290e8bc83904d11cca40a8bc4600fcbe998f25006be7daf72a4187d05a19dee4044b2984f279c9753c6
6
+ metadata.gz: 4468d9f4da47b19b93ce511f05b7873c4fc5a7115dc86ede1c02ce98736449a38509d6f4b34378ac01d5691a7119c5289b44e74e1e4ed2be62fd0a2233e101a5
7
+ data.tar.gz: 2a5679cedf2bf438148fee7cb4fc2c7d306cd0f96bbfe36b5f750a22bec8094714709cea1f6a588a265626f4334629638eee75b82ac4378cef31b493fd629f76
data/README.md CHANGED
@@ -28,7 +28,7 @@ Then use it like this:
28
28
  # Speaks "YO!"
29
29
  speech = Speech.new("YO!")
30
30
  speech.speak # invokes espeak
31
-
31
+
32
32
  # Creates hello-de.mp3 file
33
33
  speech = Speech.new("Hallo Welt", voice: "de")
34
34
  speech.save("hello-de.mp3") # invokes espeak + lame
@@ -36,19 +36,20 @@ speech.save("hello-de.mp3") # invokes espeak + lame
36
36
  # Lists voices
37
37
  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"]
38
38
 
39
- # Find particular voice
39
+ # Find particular voice
40
40
  Voice.find_by_language('en') #<ESpeak::Voice:0x007fe1d3806be8 @language="en", @name="default", @gender="M", @file="default">
41
41
  ```
42
42
 
43
43
  Features
44
44
  --------
45
45
 
46
- Currently only subset of espeak features is supported.
46
+ Currently only subset of espeak features is supported.
47
47
 
48
48
  ```ruby
49
- :voice => 'en' # use voice file of this name from espeak-data/voices
50
- :pitch => 50 # pitch adjustment, 0 to 99
51
- :speed => 170 # speed in words per minute, 80 to 370
49
+ :voice => 'en' # use voice file of this name from espeak-data/voices
50
+ :pitch => 50 # pitch adjustment, 0 to 99
51
+ :speed => 170 # speed in words per minute, 80 to 370
52
+ :capital => 170 # increase emphasis (pitch) of capitalized words, 1 to 40 (for natural sound, can go higher)
52
53
  ```
53
54
 
54
55
  These are default values, and they can be easily overridden:
@@ -1,55 +1,58 @@
1
- require 'open3.rb'
2
-
3
1
  module ESpeak
4
2
  class Speech
5
3
  attr_reader :options, :text
6
-
4
+
7
5
  # filename - The file that will be generated
8
6
  # options - Posible key, values
9
7
  # :voice - use voice file of this name from espeak-data/voices. ie 'en', 'de', ...
10
8
  # :pitch - pitch adjustment, 0 to 99
11
9
  # :speed - speed in words per minute, 80 to 370
12
- # :quiet - remove printing to stdout. Affects only lame (default false)
13
- #
10
+ # :capital - increase emphasis of capitalized letters by raising pitch by this amount
11
+ # no range given in man but good range is 10-40 to start
12
+ # :quiet - remove printing to stdout. Affects only lame (default false)
13
+ #
14
14
  def initialize(text, options={})
15
15
  @text = text
16
16
  @options = options
17
17
  end
18
18
 
19
- # Speaks text
20
- #
19
+ # Speaks text
20
+ #
21
21
  def speak
22
- system(espeak_command(command_options))
22
+ IO.popen(espeak_command(command_options), 'r').read
23
23
  end
24
24
 
25
- # Generates mp3 file as a result of
26
- # Text-To-Speech conversion.
27
- #
25
+ # Generates mp3 file as a result of
26
+ # Text-To-Speech conversion.
27
+ #
28
28
  def save(filename)
29
- system(espeak_command(command_options, "--stdout") + " | " + lame_command(filename, command_options))
29
+ speech = bytes_wav
30
+ res = IO.popen(lame_command(filename, command_options), 'r+') do |process|
31
+ process.write(speech)
32
+ process.close_write
33
+ process.read
34
+ end
35
+ res.to_s
30
36
  end
31
37
 
32
38
  # Returns mp3 file bytes as a result of
33
39
  # Text-To-Speech conversion.
34
40
  #
35
41
  def bytes()
36
- stdout_str, stderr_str, process = Open3.capture3(espeak_command(command_options, "--stdout") + " | " + std_lame_command(command_options))
37
- stdout_str
42
+ speech = bytes_wav
43
+ res = IO.popen(std_lame_command(command_options), 'r+') do |process|
44
+ process.write(speech)
45
+ process.close_write
46
+ process.read
47
+ end
48
+ res.to_s
38
49
  end
39
50
 
40
51
  # Returns wav file bytes as a result of
41
52
  # Text-To-Speech conversion.
42
53
  #
43
54
  def bytes_wav()
44
- stdout_str, stderr_str, process = Open3.capture3(espeak_command(command_options, "--stdout"))
45
- stdout_str
46
- end
47
-
48
- # espeak dies handling some chars
49
- # this function sanitizes text
50
- #
51
- def sanitized_text
52
- @text.gsub(/(!|\?|"|`|\\)/, ' ').strip
55
+ IO.popen(espeak_command(command_options, "--stdout"), 'r').read
53
56
  end
54
57
 
55
58
  private
@@ -58,7 +61,7 @@ module ESpeak
58
61
  default_options.merge(symbolize_keys(options))
59
62
  end
60
63
 
61
- # Although espeak itself has default options
64
+ # Although espeak itself has default options
62
65
  # I'm defining them here for easier generating
63
66
  # command (with simple hash.merge)
64
67
  #
@@ -66,11 +69,12 @@ module ESpeak
66
69
  { :voice => 'en',
67
70
  :pitch => 50,
68
71
  :speed => 170,
72
+ :capital => 1,
69
73
  :quiet => true }
70
74
  end
71
75
 
72
76
  def espeak_command(options, flags="")
73
- %|espeak "#{sanitized_text}" #{flags} -v#{options[:voice]} -p#{options[:pitch]} -s#{options[:speed]}|
77
+ ['espeak', "#{@text}", "#{flags}", "-v#{options[:voice]}", "-p#{options[:pitch]}", "-k#{options[:capital]}", "-s#{options[:speed]}"]
74
78
  end
75
79
 
76
80
  def std_lame_command(options)
@@ -78,7 +82,7 @@ module ESpeak
78
82
  end
79
83
 
80
84
  def lame_command(filename, options)
81
- "lame -V2 - #{filename} #{'--quiet' if options[:quiet] == true}"
85
+ ['lame', '-V2', '-', "#{filename}", "#{'--quiet' if options[:quiet] == true}"]
82
86
  end
83
87
 
84
88
  def symbolize_keys(hash)
@@ -4,11 +4,6 @@ require 'fileutils'
4
4
  class SpeechTest < Test::Unit::TestCase
5
5
  include ESpeak
6
6
 
7
- def test_sanitized_text
8
- assert_equal "Hello", Speech.new("Hello!").sanitized_text
9
- assert_equal "Hello World", Speech.new("Hello?World").sanitized_text
10
- end
11
-
12
7
  def test_save
13
8
  FileUtils.rm_rf("test/tmp")
14
9
  FileUtils.mkdir_p("test/tmp")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: espeak-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dejan Simic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-24 00:00:00.000000000 Z
11
+ date: 2016-05-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: espeak-ruby is small Ruby API for utilizing ‘espeak’ and ‘lame’ to create
14
14
  Text-To-Speech mp3 files
@@ -52,3 +52,4 @@ specification_version: 4
52
52
  summary: espeak-ruby is small Ruby API for utilizing ‘espeak’ and ‘lame’ to create
53
53
  Text-To-Speech mp3 files
54
54
  test_files: []
55
+ has_rdoc: