Skip to content

Conversation

@p-siegel
Copy link

Append 's' to speechContext in order to work with the API. Stracktrace without:
File "/usr/local/lib/python2.7/dist-packages/google/cloud/speech/sample.py", line 300, in recognize
profanity_filter, speech_contexts)
File "/usr/local/lib/python2.7/dist-packages/google/cloud/speech/_http.py", line 165, in recognize
method='POST', path='speech:recognize', data=data)
File "/usr/local/lib/python2.7/dist-packages/google/cloud/_http.py", line 303, in api_request
error_info=method + ' ' + url)
google.cloud.exceptions.BadRequest: 400 Invalid JSON payload received. Unknown name "speech_context" at 'config': Cannot find field. (POST https://speech.googleapis.com/v1/speech:recognize)
Aborted (core dumped)

Append 's' to speechContext in order to work with the API. Stracktrace without:
  File "/usr/local/lib/python2.7/dist-packages/google/cloud/speech/sample.py", line 300, in recognize
    profanity_filter, speech_contexts)
  File "/usr/local/lib/python2.7/dist-packages/google/cloud/speech/_http.py", line 165, in recognize
    method='POST', path='speech:recognize', data=data)
  File "/usr/local/lib/python2.7/dist-packages/google/cloud/_http.py", line 303, in api_request
    error_info=method + ' ' + url)
google.cloud.exceptions.BadRequest: 400 Invalid JSON payload received. Unknown name "speech_context" at 'config': Cannot find field. (POST https://speech.googleapis.com/v1/speech:recognize)
Aborted (core dumped)
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@googlebot googlebot added the cla: no This human has *not* signed the Contributor License Agreement. label Jun 30, 2017
@p-siegel
Copy link
Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Jun 30, 2017
@tseaver tseaver added the api: speech Issues related to the Speech-to-Text API. label Jun 30, 2017
@tseaver
Copy link
Contributor

tseaver commented Jun 30, 2017

@p-siegel Thanks for the patch! We also need to adjust the tests to match (i.e., in tests/unit/test_client.py).

@tseaver
Copy link
Contributor

tseaver commented Jun 30, 2017

It would be best if we could add / modify a system test which exercises the failing case, too.

@dhermes
Copy link
Contributor

dhermes commented Jun 30, 2017

@tseaver We could just send commits to this PR to help it along?

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@googlebot googlebot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Jun 30, 2017
@tseaver
Copy link
Contributor

tseaver commented Jun 30, 2017

The speech system tests are failing on master for me at the moment (#3392) so I'm not going to hold this PR up for them (and there are tests which set speech_contexts, anyway).

@tseaver tseaver merged commit 2a4511c into googleapis:master Jun 30, 2017
@dhermes
Copy link
Contributor

dhermes commented Jun 30, 2017

SGTM @tseaver

@p-siegel p-siegel deleted the patch-1 branch July 3, 2017 07:49
@zoell
Copy link

zoell commented Jul 3, 2017

Hello,

I just tried these examples over the weekend here but it seems it works only when I specified one word:
https://cloud.google.com/speech/docs/basics#phrase-hints

So if I add "shwazil" to speech_contexts, that works, but if I add ["shwazil", "hoful"], it just recognizes shwazil but leaves the hoful word untouched and it is not recognized properly.

Is this example working for you?

Thanks,
zoell

@p-siegel
Copy link
Author

p-siegel commented Jul 4, 2017

Hi,
I just tried the example. The same is happening to me. When I only provide a single word, that word is recognized. But when I specify both words, only "shwazil" is recognized.

@tseaver
Copy link
Contributor

tseaver commented Jul 5, 2017

@zoell, are you running from a Git clone, or from the released version on PyPI. If the latter, this PRs changes have not yet been released.

@tseaver
Copy link
Contributor

tseaver commented Jul 5, 2017

@p-siegel Can you provide a Python sample of how you pass in the multiple words? I'm assuming something like:

sample = client.sample(
            encoding=speech.Encoding.FLAC,
            sample_rate_hertz=16000,
            source_uri='gs://speech-demo/shwazil_hoful.flac',
        )
results = sample.recognize(
    language_code='en-US',
    speech_contexts=['hoful', 'shwazil'],
)

or else maybe:

sample = client.sample(
            encoding=speech.Encoding.FLAC,
            sample_rate_hertz=16000,
            source_uri='gs://speech-demo/shwazil_hoful.flac',
        )
results = sample.recognize(
    language_code='en-US',
    speech_contexts=['shwazil hoful'],
)

@tseaver
Copy link
Contributor

tseaver commented Jul 5, 2017

Here is what I get:

>>> r1 = sample.recognize(
...     language_code='en-US',
...     speech_contexts=['hoful', 'shwazil'],
... )
>>> r1[0].alternatives[0].__dict__
{'_confidence': 0.7818678021430969, '_transcript': u"it's a shwazil huffel day"}
>>> r2 = sample.recognize(
...     language_code='en-US',
...     speech_contexts=['shwazil hoful'],
... )
>>> r2[0].alternatives[0].__dict__
{'_confidence': 0.7818678021430969, '_transcript': u"it's a shwazil huffel day"}

@p-siegel
Copy link
Author

p-siegel commented Jul 5, 2017

@tseaver Here is what I used: Looks pretty much the same.

with open('./shwazil_hoful.flac', 'rb') as speech:
    speech_content = speech.read()

sample = client.sample(
    speech_content,
    source_uri=None,
    encoding='FLAC', 
    sample_rate_hertz=16000
)
	
response = sample.recognize(
    language_code='en-US',
    speech_contexts=['shwazil', 'hoful']
) 

The response is exactly the same as yours.

@zoell
Copy link

zoell commented Jul 5, 2017

I installed the PyPI version but changed _http.py to this one.
Same is for me as yours.

@tseaver
Copy link
Contributor

tseaver commented Jul 5, 2017

This is an issue with the back-end API sample doc. I just tried the same request in the "Try It!" form for the recognize API docs:

{
  "config": {
    "encoding": "FLAC",
    "sampleRateHertz": 16000,
    "languageCode": "en-US",
    "speechContexts": [
      {
        "phrases": [
          "hoful",
          "shwazil"
        ]
      }
    ]
  },
  "audio": {
    "uri": "gs://speech-demo/shwazil_hoful.flac"
  }
}

with the same result:

{
  "results": [
    {
      "alternatives": [
        {
          "transcript": "it's a shwazil huffel day",
          "confidence": 0.7818678
        }
      ]
    }
  ]
}

@dhermes dhermes mentioned this pull request Jul 14, 2017
landrito pushed a commit to landrito/google-cloud-python that referenced this pull request Aug 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: speech Issues related to the Speech-to-Text API. cla: no This human has *not* signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants