1

This is a forked problem off of this question: flac: "ERROR: input file has an ID3v2 tag" (it doesn't). I've solved the initial issue there but that didn't resolve one problem I was having, so I'm going to introduce it separately here.

I'm using a Ruby gem called speech2text to convert an audio file into (approximated) text. Calling it on the command line works fine (Mac Terminal). However, the following Java code:

String[] cmd = {"speech2text", "tmp/audio/pop-test-audio.wav"};

    ProcessBuilder builder = new ProcessBuilder(cmd);
    builder.redirectErrorStream(true);
    Process process = builder.start();

Only receives this back from the process streams:

/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 /Library/Ruby/Gems/1.8/gems/speech2text-0.3.4/bin/speech2text:11
from /usr/bin/speech2text:19:in `load'
from /usr/bin/speech2text:19

I don't know anything about Ruby, hence my lightweight use of the library through Java. I really can't tell what's going on here, but I know that it works when executed in exactly the same way from the Terminal. Has anyone got any idea what might be causing this?

Community
  • 1
  • 1
mtrc
  • 1,317
  • 3
  • 16
  • 39
  • Hmm. The path tmp/audio... is actually within the folder of the Java Eclipse project. It worked for other programs but you might be right - it might be that Ruby isn't as welcoming. I'll check it, thanks! – mtrc Mar 25 '12 at 16:37
  • Okay, full paths did not work. I tested running it on an incorrect path, and it threw a different error so we can probably rule that out. – mtrc Mar 25 '12 at 16:40

2 Answers2

0

I have had similar issues trying to run jslint.js (for node.js). I actually did better running bash first, then print writing in my commands that way, but even that had problems as I recall.

Basically the problem is that executing things with Java can fail when environment settings that would otherwise be available are not loaded. This can be a tough one to solve.

ControlAltDel
  • 33,923
  • 10
  • 53
  • 80
  • Okay. I like the idea of actually running a Terminal and pumping stuff through that way! How hideous, kinda, but if it works I'll try it! – mtrc Mar 25 '12 at 16:41
  • Okay, this has proved difficult - while in theory that worked, I can't work out how to get the stream of the process launched by the process (if you see what I mean) so that might not be the option. – mtrc Mar 25 '12 at 18:41
0

You could also ditch the terminal and try JRuby. It's just as fast as the normal Ruby VM and is easier to integrate with Java.

vgel
  • 3,225
  • 1
  • 21
  • 35
  • Now there's an idea. Awesome looking library, I'll take a look. Thanks! – mtrc Mar 25 '12 at 18:43
  • This has proven difficulty in itself. speech2text is a gem (I believe) but I'm so unfamiliary with Ruby I don't know how to write the requisite Java code to execute it. In `irb` I can run the sample Ruby code, but actually writing a Ruby script it fails to recognise the initial import, so there's further complications. Frustrating! – mtrc Mar 26 '12 at 16:35
  • I've found some better resources and I have to say I think this was the way to go. While I can't solve the original problem, this answer got me to a solution. Thanks! – mtrc Mar 26 '12 at 22:46