diff --git a/lib/espeak/speech.rb b/lib/espeak/speech.rb index c8e4ca5..30d0234 100644 --- a/lib/espeak/speech.rb +++ b/lib/espeak/speech.rb @@ -28,9 +28,11 @@ def speak # Generates mp3 file as a result of # Text-To-Speech conversion. + # this method takes an optional speech param (bytes to save) + # can be used with the combined output of many text to speech conversions # - def save(filename) - speech = bytes_wav + def save(filename, speech = nil) + speech = bytes_wav if speech.nil? res = IO.popen(lame_command(filename, command_options), 'r+') do |process| process.write(speech) process.close_write diff --git a/test/cases/speech_test.rb b/test/cases/speech_test.rb index 5fd7494..d70831a 100644 --- a/test/cases/speech_test.rb +++ b/test/cases/speech_test.rb @@ -13,4 +13,14 @@ def test_save assert File.exist?('test/tmp/test.mp3'), 'Mp3 file not generated' FileUtils.rm_rf('test/tmp') end + + def test_save_with_bytes + FileUtils.rm_rf('test/tmp') + FileUtils.mkdir_p('test/tmp') + bytes = Speech.new('Hello!').bytes_wav + assert Speech.new('').save('test/tmp/test_bytes.mp3', bytes) + assert File.exist?('test/tmp/test_bytes.mp3'), 'Mp3 file not generated' + FileUtils.rm_rf('test/tmp') + end + end