Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save bytes #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/espeak/speech.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/cases/speech_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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