Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import json
  2. import os
  3. import sys
  4. from watson_developer_cloud import SpeechToTextV1
  5.  
  6. def transcribe_audio(audio_file_name) :
  7. IBM_USERNAME = "yourusername"
  8.  
  9. IBM_PASSWORD = "yourpassword"
  10. #what changes should be made here instead of username and password
  11.  
  12. stt = SpeechToTextV1(username=IBM_USERNAME, password=IBM_PASSWORD)
  13. audio_file = open(audio_file_name, "rb")
  14. json_file = os.path.abspath("america")+".json";
  15. with open(json_file, 'w') as fp:
  16. result = stt.recognize(audio_file,timestamps=True,content_type='audio/wav', inactivity_timeout =-1,word_confidence = True)
  17. result.get_result()
  18. json.dump(result, fp, indent=2)
  19. script = "Script is : "
  20. for rows in result['results']:
  21. script += rows['alternatives'][0]['transcript']
  22. print(script)
  23. transcribe_audio("america.wav")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement