Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from watson_developer_cloud import NaturalLanguageClassifierV1, SpeechToTextV1, TextToSpeechV1
- # Speech to Text
- speech_to_text = SpeechToTextV1(
- username="your username",
- password="your password")
- input_audio_file = open("speech.wav", "rb")
- response = speech_to_text.recognize(input_audio_file, content_type="audio/wav")
- transcript = response["results"][0]["alternatives"][0]["transcript"]
- print transcript
- # Natural Language Classifier
- natural_language_classifier = NaturalLanguageClassifierV1(
- username="your username",
- password="your password")
- classifier_id = "your classifier ID"
- response = natural_language_classifier.classify(classifier_id, transcript)
- detected_class = response["top_class"]
- print detected_class
- # Text to Speech
- text_to_speech = TextToSpeechV1(
- username="your username",
- password="your password")
- output_audio_file = open("output.wav", "wb")
- response_text = "I detected this class: " + detected_class
- audio_data = text_to_speech.synthesize(response_text, accept="audio/wav")
- output_audio_file.write(audio_data)
- print response_text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement