Skip to content

Commit

Permalink
feat: adds new multi region sample (#96)
Browse files Browse the repository at this point in the history
* I updated the comment on the transcribe_async file to reflect time limitations on local files for the long_running_recognize

* I updated the comment on the transcribe_async file to reflect time limitations on local files for the long_running_recognize

* docs: I updated the comment on the transcribe_async file to reflect time limitations on local files for the long_running_recognize

* chore: I updated the comments on the transcribe_async file to reflect time limitations on local files for the long_running_recognize

* fix: resolved conflicts

    pick f510e8f chore: I updated the comments on the transcribe_async file to reflect time limitations on local files for the long_running_recognize

* chore: added a profanity filter sample

* docs: fixed region tag

* chore: updated the quickstart to gcs

* feat: adds new multi-region sample

* fix: migrated to speech 2.0.0

* fix: fixed lint issues

* fix: deleted a duplicate line that calls the recognizer

* docs: repaired region tag mismatch

* chore: formatting

* chore: added ]

* docs: udated documentation to point to python-speech insteadof python-docs-samples

* docs: udated documentation to point to python-speech instead of python-docs-samples

* docs: udated documentation to point to python-speech instead of python-docs-samples

* docs: udated documentation to point to python-speech instead of python-docs-samples

* docs: udated documentation to point to python-speech instead of python-docs-samples

* docs: udated documentation to point to python-speech instead of python-docs-samples

* docs: udated documentation to point to python-speech instead of python-docs-samples

* docs: udated documentation to point to python-speech instead of python-docs-samples

* docs: udated documentation to point to python-speech instead of python-docs-samples

* docs: udated documentation to point to python-speech instead of python-docs-samples

* docs: udated documentation to point to python-speech instead of python-docs-samples

* docs: udated documentation to point to python-speech instead of python-docs-samples

* docs: udated documentation to point to python-speech instead of python-docs-samples

* fix: applied suggested changes

* fix: applied suggested changes

* fix: linting
  • Loading branch information
b-loved-dreamer authored Dec 15, 2020
1 parent 7f60ac6 commit 983f6bf
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python

# Copyright 2020 Google LLC
#
# 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.


def sync_recognize_with_multi_region_gcs():
# [START speech_multi_region]

# Imports the Google Cloud client library
from google.cloud import speech
from google.api_core import client_options

# Instantiates a client

# [START speech_multi_region_client]

# Pass an additional argument, ClientOptions, to specify the new endpoint.
client_options = client_options.ClientOptions(
api_endpoint="eu-speech.googleapis.com"
)

client = speech.SpeechClient(client_options=client_options)
# [END speech_multi_region_client]

# The name of the audio file to transcribe
gcs_uri = "gs://cloud-samples-data/speech/brooklyn_bridge.raw"

audio = speech.RecognitionAudio(uri=gcs_uri)

config = speech.RecognitionConfig(
encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,
sample_rate_hertz=16000,
language_code="en-US",
)

# Detects speech in the audio file
response = client.recognize(config=config, audio=audio)

for result in response.results:
print("Transcript: {}".format(result.alternatives[0].transcript))
# [END speech_multi_region]


sync_recognize_with_multi_region_gcs()
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2020 Google LLC
# 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.


import multi_region


def test_multi_region(capsys):
multi_region.sync_recognize_with_multi_region_gcs()
out, _ = capsys.readouterr()
assert "Transcript: how old is the Brooklyn Bridge" in out
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@
python transcribe.py gs://cloud-samples-tests/speech/brooklyn.flac
"""

import argparse


# [START speech_recognize_with_profanity_filter_gcs]
def sync_recognize_with_profanity_filter_gcs(storage_uri):
def sync_recognize_with_profanity_filter_gcs(gcs_uri):

from google.cloud import speech

client = speech.SpeechClient()

audio = {"uri": storage_uri}
audio = {"uri": gcs_uri}

config = speech.RecognitionConfig(
encoding=speech.RecognitionConfig.AudioEncoding.FLAC,
Expand All @@ -46,10 +44,6 @@ def sync_recognize_with_profanity_filter_gcs(storage_uri):

# [END speech_recognize_with_profanity_filter_gcs]

if __name__ == "__main__":
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
)
parser.add_argument("path", help="GCS path for audio file to be recognized")
args = parser.parse_args()
sync_recognize_with_profanity_filter_gcs(args.path)
sync_recognize_with_profanity_filter_gcs(
"gs://cloud-samples-tests/speech/brooklyn.flac"
)
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def transcribe_file(speech_file):
sample_rate_hertz=16000,
language_code="en-US",
)

# [START speech_python_migration_async_response]

operation = client.long_running_recognize(config=config, audio=audio)
# [END speech_python_migration_async_request]

Expand Down

0 comments on commit 983f6bf

Please sign in to comment.