Skip to content

Commit cc2137d

Browse files
nitsanshaiAJ Morozoffparthea
authored
docs(samples): Update code samples for adaptation and VAD (#462)
Co-authored-by: AJ Morozoff <[email protected]> Co-authored-by: Anthonios Partheniou <[email protected]>
1 parent bcc47c1 commit cc2137d

15 files changed

+390
-17
lines changed

speech/snippets/adaptation_v2_custom_class_reference.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def adaptation_v2_custom_class_reference(project_id, recognizer_id, phrase_set_i
4444
request = cloud_speech.CreateCustomClassRequest(
4545
parent=f"projects/{project_id}/locations/global",
4646
custom_class_id=custom_class_id,
47-
custom_class=cloud_speech.CustomClass(items=[{"value": "Keem"}]))
47+
custom_class=cloud_speech.CustomClass(items=[{"value": "fare"}]))
4848

4949
operation = client.create_custom_class(request=request)
5050
custom_class = operation.result()
@@ -70,10 +70,6 @@ def adaptation_v2_custom_class_reference(project_id, recognizer_id, phrase_set_i
7070
auto_decoding_config={}, adaptation=adaptation
7171
)
7272

73-
print(custom_class)
74-
print(phrase_set)
75-
print(config)
76-
7773
request = cloud_speech.RecognizeRequest(
7874
recognizer=recognizer.name, config=config, content=content
7975
)

speech/snippets/adaptation_v2_custom_class_reference_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ def test_adaptation_v2_custom_class_reference(capsys):
4848
phrase_set_id = "phrase-set-" + str(uuid4())
4949
custom_class_id = "custom-class-" + str(uuid4())
5050
response = adaptation_v2_custom_class_reference.adaptation_v2_custom_class_reference(
51-
project_id, recognizer_id, phrase_set_id, custom_class_id, os.path.join(RESOURCES, "baby_keem.wav")
51+
project_id, recognizer_id, phrase_set_id, custom_class_id, os.path.join(RESOURCES, "fair.wav")
5252
)
5353

5454
assert re.search(
55-
r"play Baby Keem",
55+
r"the word is fare",
5656
response.results[0].alternatives[0].transcript,
5757
re.DOTALL | re.I,
5858
)

speech/snippets/adaptation_v2_inline_custom_class.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def adaptation_v2_inline_custom_class(project_id, recognizer_id, audio_file):
4141
content = f.read()
4242

4343
# Build inline phrase set to produce a more accurate transcript
44-
phrase_set = cloud_speech.PhraseSet(phrases=[{"value": "${keem}", "boost": 20}])
45-
custom_class = cloud_speech.CustomClass(name="keem", items=[{"value": "Keem"}])
44+
phrase_set = cloud_speech.PhraseSet(phrases=[{"value": "${fare}", "boost": 20}])
45+
custom_class = cloud_speech.CustomClass(name="fare", items=[{"value": "fare"}])
4646
adaptation = cloud_speech.SpeechAdaptation(
4747
phrase_sets=[
4848
cloud_speech.SpeechAdaptation.AdaptationPhraseSet(

speech/snippets/adaptation_v2_inline_custom_class_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ def test_adaptation_v2_inline_custom_class(capsys):
3434

3535
recognizer_id = "recognizer-" + str(uuid4())
3636
response = adaptation_v2_inline_custom_class.adaptation_v2_inline_custom_class(
37-
project_id, recognizer_id, os.path.join(RESOURCES, "baby_keem.wav")
37+
project_id, recognizer_id, os.path.join(RESOURCES, "fair.wav")
3838
)
3939

4040
assert re.search(
41-
r"play Baby Keem",
41+
r"the word is fare",
4242
response.results[0].alternatives[0].transcript,
4343
re.DOTALL | re.I,
4444
)

speech/snippets/adaptation_v2_inline_phrase_set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def adaptation_v2_inline_phrase_set(project_id, recognizer_id, audio_file):
4141
content = f.read()
4242

4343
# Build inline phrase set to produce a more accurate transcript
44-
phrase_set = cloud_speech.PhraseSet(phrases=[{"value": "Keem", "boost": 10}])
44+
phrase_set = cloud_speech.PhraseSet(phrases=[{"value": "fare", "boost": 10}])
4545
adaptation = cloud_speech.SpeechAdaptation(
4646
phrase_sets=[
4747
cloud_speech.SpeechAdaptation.AdaptationPhraseSet(

speech/snippets/adaptation_v2_inline_phrase_set_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ def test_adaptation_v2_inline_phrase_set(capsys):
3434

3535
recognizer_id = "recognizer-" + str(uuid4())
3636
response = adaptation_v2_inline_phrase_set.adaptation_v2_inline_phrase_set(
37-
project_id, recognizer_id, os.path.join(RESOURCES, "baby_keem.wav")
37+
project_id, recognizer_id, os.path.join(RESOURCES, "fair.wav")
3838
)
3939

4040
assert re.search(
41-
r"play Baby Keem",
41+
r"the word is fare",
4242
response.results[0].alternatives[0].transcript,
4343
re.DOTALL | re.I,
4444
)

speech/snippets/adaptation_v2_phrase_set_reference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def adaptation_v2_phrase_set_reference(project_id, recognizer_id, phrase_set_id,
4444
request = cloud_speech.CreatePhraseSetRequest(
4545
parent=f"projects/{project_id}/locations/global",
4646
phrase_set_id=phrase_set_id,
47-
phrase_set=cloud_speech.PhraseSet(phrases=[{"value": "Keem", "boost": 10}]))
47+
phrase_set=cloud_speech.PhraseSet(phrases=[{"value": "fare", "boost": 10}]))
4848

4949
operation = client.create_phrase_set(request=request)
5050
phrase_set = operation.result()

speech/snippets/adaptation_v2_phrase_set_reference_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ def test_adaptation_v2_phrase_set_reference(capsys):
4141
recognizer_id = "recognizer-" + str(uuid4())
4242
phrase_set_id = "phrase-set-" + str(uuid4())
4343
response = adaptation_v2_phrase_set_reference.adaptation_v2_phrase_set_reference(
44-
project_id, recognizer_id, phrase_set_id, os.path.join(RESOURCES, "baby_keem.wav")
44+
project_id, recognizer_id, phrase_set_id, os.path.join(RESOURCES, "fair.wav")
4545
)
4646

4747
assert re.search(
48-
r"play Baby Keem",
48+
r"the word is fare",
4949
response.results[0].alternatives[0].transcript,
5050
re.DOTALL | re.I,
5151
)
Binary file not shown.
-158 KB
Binary file not shown.

0 commit comments

Comments
 (0)