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

Commit

Permalink
[translate] fix hybrid glossaries tests [(#3936)](GoogleCloudPlatform…
Browse files Browse the repository at this point in the history
  • Loading branch information
busunkim96 authored and danoscarmike committed Jul 31, 2020
1 parent 166b785 commit fc6da7c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
19 changes: 13 additions & 6 deletions samples/snippets/hybrid_glossaries/hybrid_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,28 @@ def text_to_speech(text, outfile):
client = texttospeech.TextToSpeechClient()

# Sets the text input to be synthesized
synthesis_input = texttospeech.types.SynthesisInput(ssml=ssml)
synthesis_input = texttospeech.SynthesisInput(ssml=ssml)

# Builds the voice request, selects the language code ("en-US") and
# the SSML voice gender ("MALE")
voice = texttospeech.types.VoiceSelectionParams(
voice = texttospeech.VoiceSelectionParams(
language_code='en-US',
ssml_gender=texttospeech.enums.SsmlVoiceGender.MALE)
ssml_gender=texttospeech.SsmlVoiceGender.MALE)

# Selects the type of audio file to return
audio_config = texttospeech.types.AudioConfig(
audio_encoding=texttospeech.enums.AudioEncoding.MP3)
audio_config = texttospeech.AudioConfig(
audio_encoding=texttospeech.AudioEncoding.MP3)

# Performs the text-to-speech request on the text input with the selected
# voice parameters and audio file type
response = client.synthesize_speech(synthesis_input, voice, audio_config)

request = texttospeech.SynthesizeSpeechRequest(
input=synthesis_input,
voice=voice,
audio_config=audio_config
)

response = client.synthesize_speech(request=request)

# Writes the synthetic audio to the output file.
with open(outfile, 'wb') as out:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
# limitations under the License.

import os
import re
import sys
import uuid

from hybrid_tutorial import create_glossary
from hybrid_tutorial import pic_to_text
Expand All @@ -28,14 +30,10 @@


def test_vision_standard_format():

expected_text = 'This is\na test!\n'
alt_expected_text = 'This\nis\na test!\n'

# Generate text using Vision API
text = pic_to_text('resources/standard_format.jpeg')

assert (text == expected_text) or (text == alt_expected_text)
assert re.match(r"This\s?is\s?a\s?test!\s?", text)


def test_vision_non_standard_format():
Expand All @@ -58,7 +56,7 @@ def test_create_and_delete_glossary():
from beta_snippets import delete_glossary

languages = ['fr', 'en']
glossary_name = 'test-glossary'
glossary_name = f'test-glossary-{uuid.uuid4()}'
glossary_uri = 'gs://cloud-samples-data/translation/bistro_glossary.csv'

# create_glossary will raise an exception if creation fails
Expand Down
2 changes: 1 addition & 1 deletion samples/snippets/hybrid_glossaries/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
google-cloud-translate==2.0.1
google-cloud-vision==1.0.0
google-cloud-texttospeech==1.0.1
google-cloud-texttospeech==2.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ $10
Firebase Fruit Salad
watermelon, honeydew melon,
and pineapple
$6
Compute Engine Burger
quarter-pound burger with
cheddar cheese
$10
$6
BigQuery BLT
bacon, lettuce, and tomato
sandwich
Expand Down
3 changes: 3 additions & 0 deletions samples/snippets/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
# don't recurse into hybrid_glossaries directory
norecursedirs = *

0 comments on commit fc6da7c

Please sign in to comment.