def test_recognize_speech_green_path(self, mock_hook): mock_hook.return_value.recognize_speech.return_value = True CloudSpeechToTextRecognizeSpeechOperator( # pylint: disable=no-value-for-parameter project_id=PROJECT_ID, gcp_conn_id=GCP_CONN_ID, config=CONFIG, audio=AUDIO, task_id="id").execute(context={"task_instance": Mock()}) mock_hook.assert_called_once_with(gcp_conn_id=GCP_CONN_ID) mock_hook.return_value.recognize_speech.assert_called_once_with( config=CONFIG, audio=AUDIO, retry=None, timeout=None)
def test_missing_audio(self, mock_hook): mock_hook.return_value.recognize_speech.return_value = True with self.assertRaises(AirflowException) as e: CloudSpeechToTextRecognizeSpeechOperator( # pylint: disable=no-value-for-parameter project_id=PROJECT_ID, gcp_conn_id=GCP_CONN_ID, config=CONFIG, task_id="id").execute(context={"task_instance": Mock()}) err = e.exception self.assertIn("audio", str(err)) mock_hook.assert_not_called()
# [START howto_operator_text_to_speech_synthesize] text_to_speech_synthesize_task = CloudTextToSpeechSynthesizeOperator( project_id=GCP_PROJECT_ID, input_data=INPUT, voice=VOICE, audio_config=AUDIO_CONFIG, target_bucket_name=BUCKET_NAME, target_filename=FILENAME, task_id="text_to_speech_synthesize_task", ) # [END howto_operator_text_to_speech_synthesize] # [START howto_operator_speech_to_text_recognize] speech_to_text_recognize_task = CloudSpeechToTextRecognizeSpeechOperator( project_id=GCP_PROJECT_ID, config=CONFIG, audio=AUDIO, task_id="speech_to_text_recognize_task" ) # [END howto_operator_speech_to_text_recognize] text_to_speech_synthesize_task >> speech_to_text_recognize_task # [START howto_operator_translate_speech] translate_speech_task = GcpTranslateSpeechOperator( project_id=GCP_PROJECT_ID, audio=AUDIO, config=CONFIG, target_language=TARGET_LANGUAGE, format_=FORMAT, source_language=SOURCE_LANGUAGE, model=MODEL, task_id='translate_speech_task'