Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[translate] fix hybrid glossaries tests #3936

Merged
merged 13 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions translate/cloud-client/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 translate/cloud-client/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 translate/cloud-client/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 = *