From 525f67c04d1d3ab8e9086f1c071f6ca7a5c7d630 Mon Sep 17 00:00:00 2001 From: Helena Rasche Date: Tue, 16 May 2023 10:42:23 +0200 Subject: [PATCH] needed updates to allow writing to custom location --- bin/ari-synthesize.rb | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/bin/ari-synthesize.rb b/bin/ari-synthesize.rb index 3e020bf75cb26..32cd4bcf1ec76 100755 --- a/bin/ari-synthesize.rb +++ b/bin/ari-synthesize.rb @@ -98,14 +98,22 @@ def find_duration(mp3) data['format']['duration'].to_f end -def synthesize(uncorrected_line, engine, voice: 'Amy', lang: 'en-GB', neural: true) +def synthesize(uncorrected_line, engine, voice: 'Amy', lang: 'en-GB', neural: true, output: nil) line = correct(uncorrected_line) digest = Digest::MD5.hexdigest line - mp3 = File.join(GTN_CACHE, "#{engine}-#{digest}-#{voice}.mp3") - json = File.join(GTN_CACHE, "#{engine}-#{digest}-#{voice}.json") - if File.file?(mp3) - duration = JSON.parse(File.read(json))['end'] - return mp3, json, duration.to_f + if output.nil? + mp3 = File.join(GTN_CACHE, "#{engine}-#{digest}-#{voice}.mp3") + json = File.join(GTN_CACHE, "#{engine}-#{digest}-#{voice}.json") + if File.file?(mp3) + duration = JSON.parse(File.read(json))['end'] + return mp3, json, duration.to_f + end + else + mp3 = output + json = output + '.json' + if File.file?(output) + return mp3, json, 0.0 # Todo + end end # Call our engine @@ -179,6 +187,10 @@ def parseOptions options[:file] = n end + opts.on('-oFILE', '--output=FILE', 'Location to save the file in (defaults to auto-generated location)') do |n| + options[:output] = n + end + opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v| options[:verbose] = v end @@ -206,6 +218,6 @@ def parseOptions if __FILE__ == $PROGRAM_NAME sentence, engine, options = parseOptions - mp3, = synthesize(sentence, engine, voice: options[:voice], lang: options[:lang], neural: options[:neural]) + mp3, = synthesize(sentence, engine, voice: options[:voice], lang: options[:lang], neural: options[:neural], output: options[:output]) puts mp3 end