Skip to content

Google Speech recognize.js listen not recording on Raspberry pi  #375

Closed

Description

@jmp1548

Hi All,

I am trying the run the streamingMicRecognize function in recognize.js.
Whenever I run this on my raspberry pi (with a usb mic (that works with arecord)) the recording stream end immediately.

Here is my code (modified slightly)

const streamingMicRecognize = () => {
  console.log("Stream");
  // console.dir(recognizeStream);

  const recognizeStream = speech.createRecognizeStream(config).on('error', console.error).on('data', data => {
    console.log('recongizeStream > data');
    // record.stop();
    playback(data);
    process.stdout.write(data.results);
  }).on('end', () => {
    console.log("end stream")
  });
  // console.dir(recognizeStream);

  record.start({
    sampleRateHertz: 16000, threshold: 0,
    // Other options, see https://www.npmjs.com/package/node-record-lpcm16#options
    verbose: true,
    recordProgram: 'rec', // Try also "arecord" or "sox"
    silence: '10.0'
  }).on('error', console.error).pipe(recognizeStream);

  console.log('Listening, press Ctrl+C to stop.');
  // [END speech_streaming_mic_recognize]
}

When I run this with verbose mode set to true, I get this

Stream
Recording with sample rate 16000...
Listening, press Ctrl+C to stop.
Recording 5526 bytes
End Recording 91.384ms
end stream

The recording ends before I get a chance to speak. Not sure what could be causing that. If you need any more information, please let me know.

I should also note, that this works perfectly on my mac. Seems to be specific to the pi.

Activity

  1. jmp1548 commented on May 4, 2017

    @jmp1548
    Author

    UPDATE: I had to manually set the device in the record settings. That fixed the issue for my pi. Now I have it working on both mac and pi.

      record.start({
        sampleRateHertz: 16000, threshold: 0,
        // Other options, see https://www.npmjs.com/package/node-record-lpcm16#options
        verbose: true,
        recordProgram: 'rec', // Try also "arecord" or "sox"
        silence: '10.0',
        device:  'plughw:0'
      }).on('error', console.error).pipe(recognizeStream);
    
  2. KaKi87 commented on Mar 16, 2018

    @KaKi87

    Hi, how did you find out that the proper device is plughw:0 ?

    Thanks

  3. added a commit that references this issue on Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🚨This issue needs some love.triage meI really want to be triaged.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions