Skip to content

Commit 43b1c31

Browse files
add :capital param for the -k flag in espeak to modulate pitch on capital letter words
1 parent cdef8b8 commit 43b1c31

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,28 @@ Then use it like this:
2828
# Speaks "YO!"
2929
speech = Speech.new("YO!")
3030
speech.speak # invokes espeak
31-
31+
3232
# Creates hello-de.mp3 file
3333
speech = Speech.new("Hallo Welt", voice: "de")
3434
speech.save("hello-de.mp3") # invokes espeak + lame
3535

3636
# Lists voices
3737
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"]
3838

39-
# Find particular voice
39+
# Find particular voice
4040
Voice.find_by_language('en') #<ESpeak::Voice:0x007fe1d3806be8 @language="en", @name="default", @gender="M", @file="default">
4141
```
4242

4343
Features
4444
--------
4545

46-
Currently only subset of espeak features is supported.
46+
Currently only subset of espeak features is supported.
4747

4848
```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)
5253
```
5354

5455
These are default values, and they can be easily overridden:

lib/espeak/speech.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,30 @@
33
module ESpeak
44
class Speech
55
attr_reader :options, :text
6-
6+
77
# filename - The file that will be generated
88
# options - Posible key, values
99
# :voice - use voice file of this name from espeak-data/voices. ie 'en', 'de', ...
1010
# :pitch - pitch adjustment, 0 to 99
1111
# :speed - speed in words per minute, 80 to 370
12-
# :quiet - remove printing to stdout. Affects only lame (default false)
13-
#
12+
# :capital - increase emphasis of capitalized letters by raising pitch by this amount
13+
# no range given in man but good range is 10-40 to start
14+
# :quiet - remove printing to stdout. Affects only lame (default false)
15+
#
1416
def initialize(text, options={})
1517
@text = text
1618
@options = options
1719
end
1820

19-
# Speaks text
20-
#
21+
# Speaks text
22+
#
2123
def speak
2224
system(espeak_command(command_options))
2325
end
2426

25-
# Generates mp3 file as a result of
26-
# Text-To-Speech conversion.
27-
#
27+
# Generates mp3 file as a result of
28+
# Text-To-Speech conversion.
29+
#
2830
def save(filename)
2931
system(espeak_command(command_options, "--stdout") + " | " + lame_command(filename, command_options))
3032
end
@@ -58,19 +60,20 @@ def command_options
5860
default_options.merge(symbolize_keys(options))
5961
end
6062

61-
# Although espeak itself has default options
63+
# Although espeak itself has default options
6264
# I'm defining them here for easier generating
6365
# command (with simple hash.merge)
6466
#
6567
def default_options
6668
{ :voice => 'en',
6769
:pitch => 50,
6870
:speed => 170,
71+
:capital => 1,
6972
:quiet => true }
7073
end
7174

7275
def espeak_command(options, flags="")
73-
%|espeak "#{sanitized_text}" #{flags} -v#{options[:voice]} -p#{options[:pitch]} -s#{options[:speed]}|
76+
%|espeak "#{sanitized_text}" #{flags} -v#{options[:voice]} -p#{options[:pitch]} -k#{options[:capital]} -s#{options[:speed]}|
7477
end
7578

7679
def std_lame_command(options)

0 commit comments

Comments
 (0)