@@ -53,8 +53,8 @@ def pic_to_text(infile):
53
53
54
54
# [START hybrid_create_glossary]
55
55
def create_glossary (languages , project_id , glossary_name , glossary_uri ):
56
- # Creates a GCP glossary resources
57
- # Assumes you've already uploaded a glossary to Cloud Storage
56
+ # Creates a GCP glossary resource
57
+ # Assumes you've already manually uploaded a glossary to Cloud Storage
58
58
#
59
59
# ARGS
60
60
# languages: list of languages in the glossary
@@ -70,7 +70,7 @@ def create_glossary(languages, project_id, glossary_name, glossary_uri):
70
70
71
71
# Defines the languages in the glossary
72
72
# This list must match the languages in the glossary
73
- # Here, the glossary includes French and English
73
+ # Here, the glossary includes French and English
74
74
languages = ['fr' , 'en' ]
75
75
# Set information to access
76
76
glossary_uri = 'gs://cloud-samples-data/translation/bistro_glossary.csv'
@@ -87,11 +87,9 @@ def create_glossary(languages, project_id, glossary_name, glossary_uri):
87
87
language_codes_set = translate .types .Glossary .LanguageCodesSet (
88
88
language_codes = languages )
89
89
90
- # todo
91
90
gcs_source = translate .types .GcsSource (
92
91
input_uri = glossary_uri )
93
92
94
- # todo
95
93
input_config = translate .types .GlossaryInputConfig (
96
94
gcs_source = gcs_source )
97
95
@@ -101,10 +99,10 @@ def create_glossary(languages, project_id, glossary_name, glossary_uri):
101
99
language_codes_set = language_codes_set ,
102
100
input_config = input_config )
103
101
104
- parent = client .location_path (project_id , location )
102
+ resource = client .location_path (project_id , location )
105
103
106
104
# Create glossary resource
107
- operation = client .create_glossary (parent = parent , glossary = glossary )
105
+ operation = client .create_glossary (parent = resource , glossary = glossary )
108
106
109
107
return operation .result (timeout = 90 )
110
108
@@ -160,11 +158,12 @@ def delete_glossary(project_id, glossary_name):
160
158
# ARGS
161
159
# project_id: GCP project id
162
160
# glossary_name: name you gave your project's glossary
163
- # resource when you created it
161
+ # resource when you created it
164
162
#
165
163
# RETURNS
166
164
# nothing
167
165
166
+ # Designates the data center location that you want to use
168
167
location = 'us-central1'
169
168
170
169
# Instantiates a client
@@ -184,6 +183,14 @@ def delete_glossary(project_id, glossary_name):
184
183
185
184
# [START hybrid_tts]
186
185
def text_to_speech (text , outfile ):
186
+ # Generates synthetic audio from plaintext
187
+ #
188
+ # ARGS
189
+ # text: text to synthesize
190
+ # outfile: filename to use to store synthetic audio
191
+ #
192
+ # RETURNS
193
+ # nothing
187
194
188
195
# Instantiates a client
189
196
client = texttospeech .TextToSpeechClient ()
@@ -216,27 +223,30 @@ def text_to_speech(text, outfile):
216
223
def main ():
217
224
218
225
# GCP project id
219
- project_id = 'ec-gcp'
226
+ # project_id = [TODO(developer): INSERT PROJECT ID HERE]
227
+
220
228
# Photo from which to extract text
221
229
infile = "resources/example.png"
222
230
# Name of file that will hold synthetic speech
223
231
outfile = "resources/example.mp3"
232
+
224
233
# Name that will be assigned to your project's glossary resource
225
234
glossary_name = 'bistro-glossary'
226
235
# URI of glossary uploaded to Cloud Storage
227
236
glossary_uri = 'gs://cloud-samples-data/translation/bistro_glossary.csv'
237
+ # List of languages in the glossary
238
+ glossary_langs = ['fr' , 'en' ]
228
239
229
240
# delete_glossary(project_id, glossary_name)
230
- create_glossary ([ 'fr' , 'en' ] , project_id , glossary_name , glossary_uri )
241
+ create_glossary (glossary_langs , project_id , glossary_name , glossary_uri )
231
242
243
+ # photo -> detected text
232
244
text_to_translate = pic_to_text (infile )
245
+ # detected text -> translated text
233
246
text_to_speak = translate_text (text_to_translate , 'fr' , 'en' ,
234
247
project_id , glossary_name )
248
+ # translated text -> synthetic audio
235
249
text_to_speech (text_to_speak , outfile )
236
- print (text_to_translate )
237
- print ("____" )
238
- print (text_to_speak )
239
-
240
250
# [END hybrid_integration]
241
251
242
252
0 commit comments