Advertisement
Guest User

Untitled

a guest
Aug 11th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. from watson_developer_cloud import NaturalLanguageClassifierV1, SpeechToTextV1, TextToSpeechV1
  2.  
  3. # Speech to Text
  4.  
  5. speech_to_text = SpeechToTextV1(
  6. username="your username",
  7. password="your password")
  8.  
  9. input_audio_file = open("speech.wav", "rb")
  10. response = speech_to_text.recognize(input_audio_file, content_type="audio/wav")
  11. transcript = response["results"][0]["alternatives"][0]["transcript"]
  12. print transcript
  13.  
  14. # Natural Language Classifier
  15.  
  16. natural_language_classifier = NaturalLanguageClassifierV1(
  17. username="your username",
  18. password="your password")
  19.  
  20. classifier_id = "your classifier ID"
  21. response = natural_language_classifier.classify(classifier_id, transcript)
  22. detected_class = response["top_class"]
  23. print detected_class
  24.  
  25. # Text to Speech
  26.  
  27. text_to_speech = TextToSpeechV1(
  28. username="your username",
  29. password="your password")
  30.  
  31. output_audio_file = open("output.wav", "wb")
  32. response_text = "I detected this class: " + detected_class
  33. audio_data = text_to_speech.synthesize(response_text, accept="audio/wav")
  34. output_audio_file.write(audio_data)
  35. print response_text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement