espeak-ruby icon indicating copy to clipboard operation
espeak-ruby copied to clipboard

espeak doesn't respect system's volume

Open utkarsh2102 opened this issue 3 years ago • 1 comments
trafficstars

Hi @dejan,

Thanks a bunch for working on this! \o/

However, I am using espeak-ruby like this:

        speech = ESpeak::Speech.new("put on charging, your battery is at #{capacity}%.")
        speech.speak

But even if the system's volume is low or on mute, ESpeak yells at full volume. :P Is there a nice way to make sure it's in sync with the system volume? Let me know if it already exists and I haven't looked thoroughly. TIA!

utkarsh2102 avatar Aug 16 '22 12:08 utkarsh2102

Hey @utkarsh2102, so I think for this, it would be enough for the library to provide the amplitude option, mentioned in the command line options here, which you could then further use in your script.

@dejan it's just a matter of adding support for the -a option in the ESpeak::Speech module which I would be happy to do. I hacked around a bit locally and the diff came out to look like the following:

diff --git a/lib/espeak/speech.rb b/lib/espeak/speech.rb
index f682905..c8e4ca5 100644
--- a/lib/espeak/speech.rb
+++ b/lib/espeak/speech.rb
@@ -12,6 +12,7 @@ module ESpeak
     #    :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
+    #    :amplitude - amplitude adjustment, 0 to 200
     #    :quiet     - remove printing to stdout. Affects only lame (default false)
     #
     def initialize(text, options = {})
@@ -73,12 +74,13 @@ module ESpeak
         pitch: 50,
         speed: 170,
         capital: 1,
+        amplitude: 100,
         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]}"]
+       "-s#{options[:speed]}", "-a#{options[:amplitude]}"]
     end
 
     def std_lame_command(options)

PS: thanks to @rajudev for pointing the issue in @utkarsh2102's repository, which prompted me to contribute to this repository!

Animesh-Ghosh avatar Sep 17 '22 15:09 Animesh-Ghosh

Hey @Animesh-Ghosh,

This is greatttt! Thank you! \o/

utkarsh2102 avatar Sep 20 '22 20:09 utkarsh2102

Hey @dejan, could you possibly take a look at this quick bug fix? This shall help us respect the system's volume whilst using the gem. TIA! :)

utkarsh2102 avatar Sep 20 '22 20:09 utkarsh2102

it's just a matter of adding support for the -a option in the ESpeak::Speech module which I would be happy to do.

@Animesh-Ghosh please create a PR and I'll merge

dejan avatar Sep 20 '22 21:09 dejan

Yay, thank you! ❤️

utkarsh2102 avatar Sep 20 '22 21:09 utkarsh2102

@Animesh-Ghosh please create a PR and I'll merge

@dejan PR #22 created. Please check it out, thanks!

Animesh-Ghosh avatar Sep 21 '22 16:09 Animesh-Ghosh

This is now available in just released v1.1.0. Thank you @utkarsh2102 and @Animesh-Ghosh.

dejan avatar Sep 24 '22 07:09 dejan

Hi @dejan,

This is now available in just released v1.1.0.

Awesome, thank you very much! Can you please re-trigger the CI? It's weirdly failing on the last commit. :(

Hopefully just re-running the pipeline should suffice.

utkarsh2102 avatar Sep 24 '22 16:09 utkarsh2102