Advertisement
Guest User

Untitled

a guest
May 3rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. from watson_developer_cloud import SpeechToTextV1
  2. import json
  3.  
  4. def speech_to_text(filename):
  5.  
  6. stt = SpeechToTextV1(username="5ff4851b-de60-45c5-9fdb-e0d7d9b866c2", password="3siYdkUyzVoj")
  7.  
  8. audio_file = open(filename,"rb")
  9.  
  10. result = json.dumps(stt.recognize(audio_file, content_type="audio/wav",model="en-UK_NarrowbandModel",continuous="true",timestamps="true",word_confidence="True",keywords=["completion","this"],keywords_threshold="0.1"), indent=2)
  11.  
  12. # print result
  13. wjdata = json.loads(result)
  14.  
  15. temp_str = ''
  16. for subs in wjdata["results"]:
  17. # print "transcript"
  18. temp_str+=subs["alternatives"][0]["transcript"]
  19. return temp_str
  20.  
  21. # print speech_to_text("clinton_200003_genome.wav")
  22.  
  23.  
  24.  
  25. # print "timestamps"
  26. # print subs["alternatives"][0]["timestamps"]
  27. # print "confidence"
  28. # print subs["alternatives"][0]["confidence"]
  29. # print "word_confidence"
  30. # print subs["alternatives"][0]["word_confidence"]
  31. # print "keywords_result"
  32. # print subs["keywords_result"]
  33. # https://www.ibm.com/watson/developercloud/doc/speech-to-text/input.html#models can select model
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement