Esempio n. 1
0
def main(input_uri, encoding, sample_rate, language_code='en-US'):
    service = cloud_speech.beta_create_Speech_stub(
        make_channel('speech.googleapis.com', 443))
    # The method and parameters can be inferred from the proto from which the
    # grpc client lib was generated. See:
    # https://github.com/googleapis/googleapis/blob/master/google/cloud/speech/v1beta1/cloud_speech.proto
    response = service.SyncRecognize(
        cloud_speech.SyncRecognizeRequest(
            config=cloud_speech.RecognitionConfig(
                # There are a bunch of config options you can specify. See
                # https://goo.gl/KPZn97 for the full list.
                encoding=encoding,  # one of LINEAR16, FLAC, MULAW, AMR, AMR_WB
                sample_rate=sample_rate,  # the rate in hertz
                # See https://g.co/cloud/speech/docs/languages for a list of
                # supported languages.
                language_code=language_code,  # a BCP-47 language tag
            ),
            audio=cloud_speech.RecognitionAudio(uri=input_uri, )),
        DEADLINE_SECS)

    # Print the recognition result alternatives and confidence scores.
    for result in response.results:
        print('Result:')
        for alternative in result.alternatives:
            print(u'  ({}): {}'.format(alternative.confidence,
                                       alternative.transcript))
Esempio n. 2
0
 def _process(self, input_file, language_code):
     if not input_file.endswith('.flac'):
         raise RuntimeError('Only flac encoding file is supported.')
     audio_content = cloud_speech.RecognitionAudio(content=open(
         input_file, 'rb').read(), )
     sample_rate = self._sample_rate(input_file)
     response = self.service.SyncRecognize(
         cloud_speech.SyncRecognizeRequest(
             config=cloud_speech.RecognitionConfig(
                 encoding=AUDIO_ENCODING,
                 sample_rate=sample_rate,
                 language_code=language_code,
             ),
             audio=audio_content), DEADLINE_SECS)
     return response
def main(input_uri, encoding, sample_rate):
    service = cloud_speech.beta_create_Speech_stub(
        make_channel('speech.googleapis.com', 443))
    # The method and parameters can be inferred from the proto from which the
    # grpc client lib was generated. See:
    # https://github.com/googleapis/googleapis/blob/master/google/cloud/speech/v1beta1/cloud_speech.proto
    response = service.SyncRecognize(
        cloud_speech.SyncRecognizeRequest(
            config=cloud_speech.RecognitionConfig(
                encoding=encoding,
                sample_rate=sample_rate,
            ),
            audio=cloud_speech.RecognitionAudio(uri=input_uri, )),
        DEADLINE_SECS)
    # Print the recognition results.
    print(response.results)
def main(input_uri, encoding, sample_rate):
    service = cloud_speech.beta_create_Speech_stub(
        make_channel('speech.googleapis.com', 443))
    # The method and parameters can be inferred from the proto from which the
    # grpc client lib was generated. See:
    # https://github.com/googleapis/googleapis/blob/master/google/cloud/speech/v1beta1/cloud_speech.proto
    response = service.SyncRecognize(
        cloud_speech.SyncRecognizeRequest(
            config=cloud_speech.RecognitionConfig(
                # There are a bunch of config options you can specify. See
                # https://goo.gl/A6xv5G for the full list.
                encoding=encoding,  # one of LINEAR16, FLAC, MULAW, AMR, AMR_WB
                sample_rate=sample_rate,  # the rate in hertz
                # See
                # https://g.co/cloud/speech/docs/best-practices#language_support
                # for a list of supported languages.
                language_code='en-US',  # a BCP-47 language tag
            ),
            audio=cloud_speech.RecognitionAudio(uri=input_uri, )),
        DEADLINE_SECS)
    # Print the recognition results.
    print(response.results)