コード例 #1
0
 def test_send_request(self):
     cls = speech_recognition.GoogleSpeechRecognition()
     randomdata = str(uuid.uuid4())
     response = cls.send_request('https://httpbin.org/post', randomdata,
                                 cls.headers)
     self.assertEqual(response.ok, True)
     resp_obj = json.loads(response.text)
     self.assertEqual(resp_obj['data'], randomdata)
     for h in cls.headers:
         self.assertEqual(resp_obj['headers'][h], cls.headers[h])
コード例 #2
0
 def test_conversion_codecs(self):
     cls = speech_recognition.GoogleSpeechRecognition()
     cls.convert_to_flac(self.input_mp3, 'mp3')  # should not raise
     cls.convert_to_flac(self.input_flac,
                         'flac')  # should work toonot raise
     # supported formats, but wrong datatype
     self.assertRaises(AudioFormatException, cls.convert_to_flac,
                       self.input_mp3, 'ogg')
     self.assertRaises(AudioFormatException, cls.convert_to_flac,
                       self.input_mp3, 'wav')
     # unsupported format
     self.assertRaises(AudioFormatException, cls.convert_to_flac,
                       self.input_mp3, 'wtf')
コード例 #3
0
 def test_conversion_no_conv_needed(self):
     cls = speech_recognition.GoogleSpeechRecognition()
     flac = open(self.input_flac, 'rb').read()
     converted = cls.convert_to_flac(self.input_flac, 'flac')
     self.assertEqual(flac, converted)
コード例 #4
0
 def test_recognize_wrong_file(self):
     cls = speech_recognition.GoogleSpeechRecognition()
     cls.send_request = self.no_server_response
     self.assertRaises(IOError, cls.recognize, '/dev/nullwtf', 'flac')
コード例 #5
0
 def test_recognize_no_server_response(self):
     cls = speech_recognition.GoogleSpeechRecognition()
     cls.send_request = self.no_server_response
     self.assertRaises(CommunicationException, cls.recognize,
                       self.input_flac, 'flac')
コード例 #6
0
 def test_recognize_valid_but_wrong_json(self):
     cls = speech_recognition.GoogleSpeechRecognition()
     cls.send_request = self.valid_but_wrong_json
     self.assertRaises(RecognitionException, cls.recognize, self.input_flac,
                       'flac')
コード例 #7
0
 def test_recognize_failure(self):
     cls = speech_recognition.GoogleSpeechRecognition()
     cls.send_request = self.no_recognition
     self.assertRaises(RecognitionException, cls.recognize, self.input_flac,
                       'flac')
コード例 #8
0
 def test_recognize_success(self):
     cls = speech_recognition.GoogleSpeechRecognition()
     cls.send_request = self.recognition_success
     result = cls.recognize(self.input_flac, format='flac')
     self.assertEqual(result['text'], 'just an example')
コード例 #9
0
 def test_conversion_mp3(self):
     cls = speech_recognition.GoogleSpeechRecognition()
     converted = cls.convert_to_flac(self.input_mp3, 'mp3')
     #this is cheated. we only check if the mp3 has been converted.
     #it would be better to really check, whether the result is really flac
     self.assertNotEqual(converted, open(self.input_flac, 'rb').read())