-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
- Loading branch information
1 parent
5b5397f
commit 6f46337
Showing
4 changed files
with
82 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# 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. | ||
|
||
""" Google Cloud Speech API sample application using the REST API for batch | ||
processing. | ||
Example usage: | ||
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): | ||
|
||
from google.cloud import speech | ||
|
||
client = speech.SpeechClient() | ||
|
||
audio = {"uri": storage_uri} | ||
|
||
config = speech.RecognitionConfig( | ||
encoding=speech.RecognitionConfig.AudioEncoding.FLAC, | ||
sample_rate_hertz=16000, | ||
language_code="en-US", | ||
profanity_filter=True, | ||
) | ||
|
||
response = client.recognize(config=config, audio=audio) | ||
|
||
for i, result in enumerate(response.results): | ||
alternative = result.alternatives[0] | ||
print(u"Transcript: {}".format(alternative.transcript)) | ||
|
||
|
||
# [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) |
24 changes: 24 additions & 0 deletions
24
google-cloud-speech/samples/snippets/profanity_filter_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# 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 re | ||
|
||
import profanity_filter | ||
|
||
|
||
def test_profanity_filter(capsys): | ||
profanity_filter.sync_recognize_with_profanity_filter_gcs( | ||
"gs://cloud-samples-tests/speech/brooklyn.flac" | ||
) | ||
out, err = capsys.readouterr() | ||
assert re.search(r"how old is the Brooklyn Bridge", out, re.DOTALL | re.I) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters