Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby Gem works on commandline and irb - fails when run as ruby script or via Java Process
    text
    copied!<p>I've been trying to get a certain Google API to work for two days now. Three different projects have been tried - one in Perl (which died very early on) one in Python (crashed and burnt at the last hurdle) and finally one in Ruby. The Ruby one actually works when called from the commandline as a standard command, i.e.:</p> <pre><code>speech2text somefile.wav </code></pre> <p>It even works if you open up <code>irb</code> and put in the sample code found on the project site:</p> <pre><code>require 'speech' audio = Speech::AudioToText.new("i-like-pickles.wav") puts audio.to_text.inspect </code></pre> <p>However, a Ruby .rb file with the above in will not work when executed with <code>ruby -rubygems somescript.rb</code>. It exits with this:</p> <pre><code>/Library/Ruby/Gems/1.8/gems/speech2text-0.3.4/lib/speech/audio_inspector.rb:50:in `initialize': undefined method `first' for nil:NilClass (NoMethodError) from /Library/Ruby/Gems/1.8/gems/speech2text-0.3.4/lib/speech/audio_splitter.rb:77:in `new' from /Library/Ruby/Gems/1.8/gems/speech2text-0.3.4/lib/speech/audio_splitter.rb:77:in `initialize' from /Library/Ruby/Gems/1.8/gems/speech2text-0.3.4/lib/speech/audio_to_text.rb:15:in `new' from /Library/Ruby/Gems/1.8/gems/speech2text-0.3.4/lib/speech/audio_to_text.rb:15:in `to_text' from script/test_s2t.rb:6 </code></pre> <p>Attempting to use the commandline binary <code>speech2text</code> from Java as a runtime process results in the same error message being fed back. The offending line it complains about is:</p> <pre><code> def initialize(file) self.duration = Duration.new(`ffmpeg -i #{file} 2&gt;&amp;1`.strip.scan(/Duration: (.*),/).first.first) end </code></pre> <p>But the idea of there actually being a problem in there seems unlikely to me, given that it works perfectly when executed in either <code>irb</code> or via the binary on a terminal.</p> <p>The real problem here is that I don't know Ruby at all - I work in Java, and I simply need this API to function. The fact that it runs in some methods tells me I probably installed it correctly, but unless I can get a .rb script to work or get it to execute externally, I can't see how to use it. I've had JRuby recommended to me, but that might be too complicated for me, as it seems it would require a manual installation of the ruby gem for JRuby, which I don't know how to do (or at least, I don't think I know how to do it!)</p> <p>Any advice on the core error message much appreciated, but if you see a clear sidestep to the problem do let me know.</p> <p>EDIT - It was, indeed, a path problem - at least on the face of it. Ruby was having trouble locating the exact files involved, and speech2text/ffmpeg was failing rather obscurely as a result. Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload