Google-cloud-node: Adding Speech_Context to the Speech API stops Recogniztion

Created on 1 Mar 2017  路  5Comments  路  Source: googleapis/google-cloud-node

It seems that the Speech Context config breaks the recognition stream.

Environment details

  • OS: *nix(Raspian, Ubuntu, etc)
  • Node.js version: 7.5
  • npm version:
  • google-cloud-node version: 0.6

Steps to reproduce

  1. require google-cloud
  2. Start Recognition Stream with a config values of
    const request = { config: { encoding: encoding, sampleRate: sampleRate, speech_context: ['one', 'two] }, interimResults: true };

    1. .pipe() audio stream to the Recognition Stream

question speech p2

Most helpful comment

We started using v1 of the Speech API (compared to v1beta1 previously), and it looks like it expects an array for speech_context now: https://github.com/googleapis/googleapis/blob/2b761d5190e3de4764fb58c312286ae043aec02d/google/cloud/speech/v1/cloud_speech.proto#L215

That would mean:

const request = {
  config: {
    encoding: encoding,
    sampleRateHertz, sampleRateHertz,
    profanityFilter: true,
    speechContexts: [
      {
        phrases: ["dog", "cat"]
      }
    ],
    languageCode: languageCode
  }
}

Sorry for the trouble. I opened an issue to fix our links in the docs: https://github.com/GoogleCloudPlatform/google-cloud-node/issues/2219

All 5 comments

Looks like your code specifying speech_context, but that should be speechContext?
Did you know what happens on the recognition streams? Is there any errors reported?

@LibertyBeta I believe @jmuk caught the issue with speech_context vs speechContext, but please let us know if this is still an issue.

Actually, this does not seem to be resolved (at least in version 0.9.0 from npm)-trying to supply the speech context any which way (see below request config) results in the following error for me:

Interestingly, passing the additional "profanityFilter" config param works fine.

  const request = {
    config: {
      encoding: encoding,
      sampleRateHertz: sampleRateHertz,
      profanityFilter: true,
      // speechContext: {"phrases": ["dog", "cat"]},
      //speech_context: {"phrases": ["dog", "cat"]},
      //speechContext: ["dog", "cat"],
      //speech_context: ["dog", "cat"],
      languageCode: languageCode
    }
  };
Error: .google.cloud.speech.v1.RecognitionConfig#speechContext is not a field: undefined
    at Error (native)
    at MessagePrototype.set (/Users/arnolda/GitHub/nodejs-docs-samples/speech/node_modules/protobufjs/dist/protobuf.js:2490:35)
    at MessagePrototype.set (/Users/arnolda/GitHub/nodejs-docs-samples/speech/node_modules/protobufjs/dist/protobuf.js:2483:38)
    at Message (/Users/arnolda/GitHub/nodejs-docs-samples/speech/node_modules/protobufjs/dist/protobuf.js:2411:34)
    at Element.ProtoBuf.Reflect.ElementPrototype.verifyValue (/Users/arnolda/GitHub/nodejs-docs-samples/speech/node_modules/protobufjs/dist/protobuf.js:1925:28)
    at T.ProtoBuf.Reflect.FieldPrototype.verifyValue (/Users/arnolda/GitHub/nodejs-docs-samples/speech/node_modules/protobufjs/dist/protobuf.js:3499:33)
    at MessagePrototype.set (/Users/arnolda/GitHub/nodejs-docs-samples/speech/node_modules/protobufjs/dist/protobuf.js:2493:59)
    at MessagePrototype.set (/Users/arnolda/GitHub/nodejs-docs-samples/speech/node_modules/protobufjs/dist/protobuf.js:2483:38)
    at Message (/Users/arnolda/GitHub/nodejs-docs-samples/speech/node_modules/protobufjs/dist/protobuf.js:2411:34)
    at Element.ProtoBuf.Reflect.ElementPrototype.verifyValue (/Users/arnolda/GitHub/nodejs-docs-samples/speech/node_modules/protobufjs/dist/protobuf.js:1925:28)

We started using v1 of the Speech API (compared to v1beta1 previously), and it looks like it expects an array for speech_context now: https://github.com/googleapis/googleapis/blob/2b761d5190e3de4764fb58c312286ae043aec02d/google/cloud/speech/v1/cloud_speech.proto#L215

That would mean:

const request = {
  config: {
    encoding: encoding,
    sampleRateHertz, sampleRateHertz,
    profanityFilter: true,
    speechContexts: [
      {
        phrases: ["dog", "cat"]
      }
    ],
    languageCode: languageCode
  }
}

Sorry for the trouble. I opened an issue to fix our links in the docs: https://github.com/GoogleCloudPlatform/google-cloud-node/issues/2219

Thanks for the quick reply. I can confirm that the configuration you supplied works as expected with the @google-cloud/speech NPM module version 0.9.0

Was this page helpful?
0 / 5 - 0 ratings