Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. from google.cloud import speech_v1
  2. from google.cloud.speech_v1 import enums
  3. import json
  4.  
  5.  
  6. import os
  7.  
  8.  
  9. os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "Transcribe-2e49d9085e13.json"
  10.  
  11. def sample_long_running_recognize():
  12. """
  13. Transcribe long audio file from Cloud Storage using asynchronous speech
  14. recognition
  15.  
  16. Args:
  17. storage_uri URI for audio file in Cloud Storage, e.g. gs://[BUCKET]/[FILE]
  18. """
  19.  
  20. client = speech_v1.SpeechClient()
  21.  
  22. storage_uri = 'gs://transcribe420/komunikatorvreme.flac'
  23.  
  24. # Sample rate in Hertz of the audio data sent
  25. sample_rate_hertz = 44100
  26.  
  27. # The language of the supplied audio
  28. language_code = "sl"
  29.  
  30. # Encoding of audio data sent. This sample sets this explicitly.
  31. # This field is optional for FLAC and WAV audio formats.
  32. encoding = enums.RecognitionConfig.AudioEncoding.FLAC
  33. config = {
  34. "sample_rate_hertz": sample_rate_hertz,
  35. "language_code": language_code,
  36. "encoding": encoding,
  37. }
  38. audio = {"uri": storage_uri}
  39.  
  40.  
  41. print(u"Waiting for operation to complete...")
  42. results = client.recognize(config, audio)
  43.  
  44.  
  45.  
  46. print(results)
  47.  
  48. #results = client.recognize(config,audio)
  49.  
  50. #print(type(results))
  51.  
  52.  
  53.  
  54. sample_long_running_recognize()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement