Skip to content

microphone input stream #157

Description

@staminna

Hi

Why isn't there streaming support?
I am looking at https://github.com/gillesdemey/node-record-lpcm16

Thanks

Activity

  1. Hgergely commented on Jul 21, 2016

    @Hgergely

    You can do it for yourself. You can start a sub-process in node with
    "arecord" and pipe it instead of file input
    I have done it. it worked.

    On 21 July 2016 at 17:43, Jorge [email protected] wrote:

    Hi

    Why isn't there streaming support?
    I am looking at https://github.com/gillesdemey/node-record-lpcm16

    Thanks

    —
    You are receiving this because you are subscribed to this thread.
    Reply to this email directly, view it on GitHub
    #157,
    or mute the thread
    https://github.com/notifications/unsubscribe-auth/AFyOcZEfv4rKSdUujKVNmZAvHd5q1Hm2ks5qX6GugaJpZM4JR_j9
    .

  2. jmdobry commented on Jul 21, 2016

    @jmdobry
    Member

    @staminna Which sample are you talking about?

  3. Hgergely commented on Jul 21, 2016

    @Hgergely

    Iam sure he is talking about streaming.js

    On Thu, 21 Jul 2016, 17:51 Jason Dobry, [email protected] wrote:

    @staminna https://github.com/staminna Which sample are you talking
    about?

    —
    You are receiving this because you commented.

    Reply to this email directly, view it on GitHub
    #157 (comment),
    or mute the thread
    https://github.com/notifications/unsubscribe-auth/AFyOcXO4d-AD7jYsRJB84kyAPdrcIrNuks5qX6OPgaJpZM4JR_j9
    .

  4. jmdobry commented on Jul 21, 2016

    @jmdobry
    Member

    Then I don't understand the question. speech/recognize_streaming.js is an example of using the Speech API's bi-directional streaming gRPC method. streamingRecognize() returns a duplex stream object.

  5. Hgergely commented on Jul 21, 2016

    @Hgergely

    This guy wants an example of how it can be used with a hardware audio input
    ( microphone) instead of audio file. I understand the question but I think
    he must understand : Firstly that this topic is not about all ways how the
    api can be used. Secondly this nodejs example is environment independent
    and cannot provide a environment dependent solution like microphone usage.
    Microphone is used totally different ways depending on the op system under
    node.

    On Thu, 21 Jul 2016, 18:29 Jason Dobry, [email protected] wrote:

    Then I don't understand the question. speech/recognize_streaming.js is an
    example of using the Speech API's bi-directional streaming gRPC method.
    streamingRecognize() returns a duplex stream object.

    —
    You are receiving this because you commented.

    Reply to this email directly, view it on GitHub
    #157 (comment),
    or mute the thread
    https://github.com/notifications/unsubscribe-auth/AFyOcSN7NokBw5tyXnD4JlTqQ6rE4dAHks5qX6yBgaJpZM4JR_j9
    .

  6. jmdobry commented on Jul 21, 2016

    @jmdobry
    Member

    Makes sense. I think the one of the biggest takeaways from the sample is that streamingRecognize() returns a duplex stream object, which means that one can do the following (borrowing from the sample):

    var grpcStream = speechService.streamingRecognize();
    grpcStream.write(streamingRecognizeRequest);
    
    readableStream
      .pipe(toRecognizeRequest)
      .pipe(grpcStream);

    where readableStream is any Node.js readable stream, e.g. file stream, http stream, recording stream from node-record-lpcm16, or whatever.

  7. Hgergely commented on Jul 21, 2016

    @Hgergely

    Yeas thats what I did. Simply replaced the readablestream with a audio
    input stream provided by linux arecord data. It works like charm but node
    record lmpcm16 can be an even better choice. Thanks Jason.

    On Thu, 21 Jul 2016, 19:53 Jason Dobry, [email protected] wrote:

    Makes sense. I think the one of the biggest takeaways from the sample that
    we have is that streamingRecognize() returns a duplex stream object,
    which means that one can do the following (borrowing from the sample):

    var grpcStream = speechService.streamingRecognize();grpcStream.write(streamingRecognizeRequest);

    readableStream
    .pipe(toRecognizeRequest)
    .pipe(grpcStream);

    where readableStream is any Node.js readable stream, e.g. file stream,
    http stream, recording stream from node-record-lpcm16, or whatever.

    —
    You are receiving this because you commented.

    Reply to this email directly, view it on GitHub
    #157 (comment),
    or mute the thread
    https://github.com/notifications/unsubscribe-auth/AFyOcU1bNA02ye2ifBD3YvqbzI9q2Nblks5qX8A3gaJpZM4JR_j9
    .

  8. staminna commented on Aug 8, 2016

    @staminna
    Author

    @jmdobry Where should this go?
    I keep getting grpcStream.write(streamingRecognizeRequest);
    ReferenceError: streamingRecognizeRequest is not defined

  9. jmdobry commented on Aug 8, 2016

    @jmdobry
    Member

    Can you show all of your code?

  10. staminna commented on Aug 9, 2016

    @staminna
    Author
  11. jmdobry commented on Aug 9, 2016

    @jmdobry
    Member

    @staminna Here's a more concise example you can try. Save it to a file and run it. You don't have to pass any arguments to the file.

    // Copyright 2016, Google, Inc.
    // Licensed under the Apache License, Version 2.0 (the "License");
    // you may not use this file except in compliance with the License.
    // You may obtain a copy of the License at
    //
    //    http://www.apache.org/licenses/LICENSE-2.0
    //
    // Unless required by applicable law or agreed to in writing, software
    // distributed under the License is distributed on an "AS IS" BASIS,
    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    // See the License for the specific language governing permissions and
    // limitations under the License.
    
    'use strict';
    
    var async = require('async');
    var fs = require('fs');
    var path = require('path');
    var grpc = require('grpc');
    var googleProtoFiles = require('google-proto-files');
    var googleAuth = require('google-auto-auth');
    var Transform = require('stream').Transform;
    var record = require('node-record-lpcm16');
    
    var PROTO_ROOT_DIR = googleProtoFiles('..');
    var protoDescriptor = grpc.load({
      root: PROTO_ROOT_DIR,
      file: path.relative(PROTO_ROOT_DIR, googleProtoFiles.speech.v1beta1)
    }, 'proto', {
      binaryAsBase64: true,
      convertFieldsToCamelCase: true
    });
    var speechProto = protoDescriptor.google.cloud.speech.v1beta1;
    
    function getSpeechService (callback) {
      var googleAuthClient = googleAuth({
        scopes: [
          'https://www.googleapis.com/auth/cloud-platform'
        ]
      });
    
      googleAuthClient.getAuthClient(function (err, authClient) {
        if (err) {
          return callback(err);
        }
    
        var credentials = grpc.credentials.combineChannelCredentials(
          grpc.credentials.createSsl(),
          grpc.credentials.createFromGoogleCredential(authClient)
        );
    
        console.log('Loading speech service...');
        var stub = new speechProto.Speech('speech.googleapis.com', credentials);
        return callback(null, stub);
      });
    }
    
    async.waterfall([
      function (cb) {
        getSpeechService(cb);
      },
      function sendRequest (speechService, cb) {
        console.log('Analyzing speech...');
        var call = speechService.streamingRecognize()
          .on('error', cb)
          .on('data', function (recognizeResponse) {
            console.log(JSON.stringify(recognizeResponse, null, 2));
          })
          .on('end', cb);
    
        // Write the initial recognize reqeust
        call.write({
          streamingConfig: {
            config: {
              encoding: 'LINEAR16',
              sampleRate: 16000
            },
            interimResults: true,
            singleUtterance: false
          }
        });
    
        var toRecognizeRequest = new Transform({ objectMode: true });
        toRecognizeRequest._transform = function (chunk, encoding, done) {
          done(null, {
            audioContent: chunk
          });
        };
    
        // Start recording
        var readableMicrophoneStream = record.start({
          sampleRate : 16000,
          verbose : true
        });
    
        // Stream the microphone audio to the Speech API
        readableMicrophoneStream
          .pipe(toRecognizeRequest)
          .pipe(call);
      }
    ], function (err) {
      if (err) {
        return console.error(err);
      }
      console.log('DONE');
    });
  12. staminna commented on Aug 17, 2016

    @staminna
    Author

    I can't seem to make this loop once JSON returns isFinal true. Can someone help me with this? I should be able to continue from there.

  13. jmdobry commented on Aug 19, 2016

    @jmdobry
    Member

    I'm not sure I understand. Perhaps use recursion to restart your stream?

  14. staminna commented on Aug 19, 2016

    @staminna
    Author

    I had all sorts of problems with recursive calls exceeding memory on using node-async-loop. This example only listens once, and exits node when it's done ( only once). I would like it to keep listening at all times and not exit once is 'DONE'.

  15. jmdobry commented on Nov 7, 2016

    @jmdobry
    Member
  16. 19 remaining items

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

Metadata

Metadata

Assignees

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