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

Microphone starts recording immediately #32

Open
Xasin opened this issue Jan 17, 2020 · 0 comments
Open

Microphone starts recording immediately #32

Xasin opened this issue Jan 17, 2020 · 0 comments

Comments

@Xasin
Copy link

Xasin commented Jan 17, 2020

I was playing around with the CMU Sphinx microphone, and I noticed something a little strange.
Whenever I use it to record something, it got the wrong audio - I am using the same code to write into a file as the example given, apart from a few tweaks to give me variable length recording time:

`rm /tmp/sphinxbuf.raw`
   File.open '/tmp/sphinxbuf.raw', 'wb' do |file|
   mic.record do
      FFI::MemoryPointer.new(:int16, 2048) do |bfr|
         while Time.now() - last_s_press < 1
            samp_count = mic.read_audio(bfr, 2048);
            file.write bfr.get_bytes(0, samp_count*2);

            sleep 0.1;
         end
      end
   end
end

This code gets executed after a slight delay, while the "mic" Instance is created right after starting the program.
The audio file that results from this seems to contain the audio that the mic captures right after initialization, not after the 'record' block begins.

It also seems like recording continues even after leaving the record block, suggesting that the 'stop_recording' call does not actually stop recording.

I believe this is due to the Linux audio system - it might immediately start queueing audio data after the audio device is opened, regardless of the call to "start recording"

Lastly, the 'close device' call is also a little dysfunctional, as it only throws the following error:

/var/lib/gems/2.3.0/gems/pocketsphinx-ruby-0.4.0/lib/pocketsphinx/api/call_helpers.rb:9:in `block in api_call': undefined method `<' for nil:NilClass (NoMethodError)
	from /var/lib/gems/2.3.0/gems/pocketsphinx-ruby-0.4.0/lib/pocketsphinx/api/call_helpers.rb:8:in `tap'
	from /var/lib/gems/2.3.0/gems/pocketsphinx-ruby-0.4.0/lib/pocketsphinx/api/call_helpers.rb:8:in `api_call'
	from /var/lib/gems/2.3.0/gems/pocketsphinx-ruby-0.4.0/lib/pocketsphinx/microphone.rb:68:in `close_device'

I am running Ruby 2.3.3p222, with a recent and self-compiled Pocketsphinx version (couldn't quite determine the version, the console commands are lacking a --version?)

This issue can easily be worked around by continuously polling and dumping unneeded data, but that strikes me as a little less elegant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant