Skip to content
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.

feat: adds new multi region sample #96

Merged
merged 33 commits into from Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f4291ad
I updated the comment on the transcribe_async file to reflect time li…
b-loved-dreamer Sep 22, 2020
093366f
I updated the comment on the transcribe_async file to reflect time li…
b-loved-dreamer Sep 22, 2020
4868a3d
docs: I updated the comment on the transcribe_async file to reflect t…
b-loved-dreamer Sep 22, 2020
092ce66
chore: I updated the comments on the transcribe_async file to reflect…
b-loved-dreamer Sep 23, 2020
d991670
fix: resolved conflicts
b-loved-dreamer Oct 3, 2020
ca09cb5
chore: added a profanity filter sample
b-loved-dreamer Dec 5, 2020
f113497
docs: fixed region tag
b-loved-dreamer Dec 5, 2020
2f92e40
chore: updated the quickstart to gcs
b-loved-dreamer Dec 9, 2020
0f8e29c
feat: adds new multi-region sample
b-loved-dreamer Dec 15, 2020
00824df
fix: migrated to speech 2.0.0
b-loved-dreamer Oct 2, 2020
2fcf8e2
fix: fixed lint issues
b-loved-dreamer Oct 5, 2020
82c0c84
fix: deleted a duplicate line that calls the recognizer
b-loved-dreamer Oct 28, 2020
f70ecc9
docs: repaired region tag mismatch
b-loved-dreamer Oct 28, 2020
fb7676a
chore: formatting
b-loved-dreamer Oct 28, 2020
9d1bdcc
chore: added ]
b-loved-dreamer Oct 29, 2020
299f03e
docs: udated documentation to point to python-speech insteadof python…
b-loved-dreamer Nov 19, 2020
8aada1f
docs: udated documentation to point to python-speech instead of pytho…
b-loved-dreamer Nov 19, 2020
2b49321
docs: udated documentation to point to python-speech instead of pytho…
b-loved-dreamer Nov 19, 2020
6cc6062
docs: udated documentation to point to python-speech instead of pytho…
b-loved-dreamer Nov 19, 2020
f7359b0
docs: udated documentation to point to python-speech instead of pytho…
b-loved-dreamer Nov 19, 2020
8f8f24c
docs: udated documentation to point to python-speech instead of pytho…
b-loved-dreamer Nov 19, 2020
03cc714
docs: udated documentation to point to python-speech instead of pytho…
b-loved-dreamer Nov 19, 2020
afe97cc
docs: udated documentation to point to python-speech instead of pytho…
b-loved-dreamer Nov 19, 2020
7fb218e
docs: udated documentation to point to python-speech instead of pytho…
b-loved-dreamer Nov 19, 2020
9124405
docs: udated documentation to point to python-speech instead of pytho…
b-loved-dreamer Nov 19, 2020
313caa7
docs: udated documentation to point to python-speech instead of pytho…
b-loved-dreamer Nov 19, 2020
a839dfd
docs: udated documentation to point to python-speech instead of pytho…
b-loved-dreamer Nov 20, 2020
cc5504c
docs: udated documentation to point to python-speech instead of pytho…
b-loved-dreamer Nov 20, 2020
2a805d9
fix: applied suggested changes
b-loved-dreamer Dec 15, 2020
81edacf
Merge branch 'master' into multiregion
b-loved-dreamer Dec 15, 2020
51da863
fix: applied suggested changes
b-loved-dreamer Dec 15, 2020
52cf537
Merge branch 'multiregion' of github.com:b-loved-dreamer/python-speec…
b-loved-dreamer Dec 15, 2020
1b4cb31
fix: linting
b-loved-dreamer Dec 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 56 additions & 0 deletions samples/snippets/multi_region.py
@@ -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()
21 changes: 21 additions & 0 deletions samples/snippets/multi_region_test.py
@@ -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
16 changes: 5 additions & 11 deletions samples/snippets/profanity_filter.py
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"
)
2 changes: 2 additions & 0 deletions samples/snippets/transcribe_async.py
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