Every line of 'speech_recognition' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
249 def recog(self, utterance_id): 250 context = rospy.get_param(self.node_name + '/speech_context', []) 251 path = self.utterance_file(utterance_id) 252 253 with io.open(path, 'rb') as audio_file: 254 content = audio_file.read() 255 256 audio = types.RecognitionAudio(content=content) 257 config = types.RecognitionConfig( 258 encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16, 259 sample_rate_hertz=self.sample_rate, 260 language_code='en-US', 261 enable_automatic_punctuation=True) 262 263 # TODO: figure out what the difference is between async and sync recog and how to use them 264 if self.async: 265 operation = self.speech_client.long_running_recognize(config, audio) 266 op_result = operation.result() 267 for result in op_result.results: 268 for alternative in result.alternatives: 269 print(alternative) 270 return alternative.transcript, alternative.confidence 271 else: 272 try: 273 # print("hi") 274 response = self.speech_client.recognize(config, audio) 275 if response.results is not None: 276 for result in response.results: 277 # print(result) 278 # print(u'Transcript: {}'.format(result.alternatives[0].transcript)) 279 # print(u'Confidence: {}'.format(result.alternatives[0].confidence)) 280 if result.alternatives[0].transcript is not None: 281 print(result.alternatives[0]) 282 return result.alternatives[0].transcript, result.alternatives[0].confidence 283 else: 284 print("Try speaking again") 285 except Exception as e: 286 rospy.logerr("Some kind of error: {}".format(e))
Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code
26 def test_google_french(self): 27 r = sr.Recognizer() 28 with sr.AudioFile(self.AUDIO_FILE_FR) as source: audio = r.record(source) 29 self.assertEqual(r.recognize_google(audio, language="fr-FR"), u"et c'est la dictée numéro 1")
31 def test_google_chinese(self): 32 r = sr.Recognizer() 33 with sr.AudioFile(self.AUDIO_FILE_ZH) as source: audio = r.record(source) 34 self.assertEqual(r.recognize_google(audio, language="zh-CN"), u"砸自己的脚")