2525 python beta_snippets.py multi-channel
2626 python beta_snippets.py multi-language
2727 python beta_snippets.py word-level-conf
28+ python beta_snippets.py spoken-punctuation-emojis
2829"""
2930
3031import argparse
@@ -291,6 +292,40 @@ def transcribe_file_with_word_level_confidence():
291292 # [END speech_transcribe_word_level_confidence_beta]
292293
293294
295+ def transcribe_file_with_spoken_punctuation_end_emojis ():
296+ """Transcribe the given audio file with spoken punctuation and emojis enabled."""
297+ # [START speech_transcribe_spoken_punctuation_emojis_beta]
298+ from google .cloud import speech_v1p1beta1 as speech
299+ from google .protobuf import wrappers_pb2
300+
301+ client = speech .SpeechClient ()
302+
303+ speech_file = "resources/commercial_mono.wav"
304+
305+ with io .open (speech_file , "rb" ) as audio_file :
306+ content = audio_file .read ()
307+
308+ audio = speech .RecognitionAudio (content = content )
309+ config = speech .RecognitionConfig (
310+ encoding = speech .RecognitionConfig .AudioEncoding .LINEAR16 ,
311+ sample_rate_hertz = 8000 ,
312+ language_code = "en-US" ,
313+ # Enable spoken punctuation
314+ enable_spoken_punctuation = wrappers_pb2 .BoolValue (value = True ),
315+ # Enable spoken emojis
316+ enable_spoken_emojis = wrappers_pb2 .BoolValue (value = True ),
317+ )
318+
319+ response = client .recognize (config = config , audio = audio )
320+
321+ for i , result in enumerate (response .results ):
322+ alternative = result .alternatives [0 ]
323+ print ("-" * 20 )
324+ print (u"First alternative of result {}" .format (i ))
325+ print (u"Transcript: {}" .format (alternative .transcript ))
326+ # [END speech_transcribe_spoken_punctuation_emojis_beta]
327+
328+
294329if __name__ == "__main__" :
295330 parser = argparse .ArgumentParser (
296331 description = __doc__ , formatter_class = argparse .RawDescriptionHelpFormatter
@@ -313,3 +348,5 @@ def transcribe_file_with_word_level_confidence():
313348 transcribe_file_with_multilanguage ()
314349 elif args .command == "word-level-conf" :
315350 transcribe_file_with_word_level_confidence ()
351+ elif args .command == "spoken-punctuation-emojis" :
352+ transcribe_file_with_spoken_punctuation_end_emojis ()
0 commit comments