コード例 #1
0
    def test_missing_audio(self, mock_hook):
        mock_hook.return_value.recognize_speech.return_value = True

        with self.assertRaises(AirflowException) as e:
            GcpSpeechToTextRecognizeSpeechOperator(
                project_id=PROJECT_ID, gcp_conn_id=GCP_CONN_ID, config=CONFIG, task_id="id"
            ).execute(context={"task_instance": mock.Mock()})

        err = e.exception
        self.assertIn("audio", str(err))
        mock_hook.assert_not_called()
コード例 #2
0
    def test_recognize_speech_green_path(self, mock_hook):
        mock_hook.return_value.recognize_speech.return_value = True

        GcpSpeechToTextRecognizeSpeechOperator(
            project_id=PROJECT_ID, gcp_conn_id=GCP_CONN_ID, config=CONFIG, audio=AUDIO, task_id="id"
        ).execute(context={"task_instance": mock.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
        )
コード例 #3
0
    def test_missing_config(self, mock_hook):
        mock_hook.return_value.recognize_speech.return_value = True

        with self.assertRaises(AirflowException) as e:
            GcpSpeechToTextRecognizeSpeechOperator(  # pylint: disable=no-value-for-parameter
                project_id=PROJECT_ID, gcp_conn_id=GCP_CONN_ID, audio=AUDIO, task_id="id"
            ).execute(context={"task_instance": Mock()})

        err = e.exception
        self.assertIn("config", str(err))
        mock_hook.assert_not_called()
コード例 #4
0
ファイル: example_gcp_speech.py プロジェクト: zyh1690/airflow
default_args = {"start_date": dates.days_ago(1)}

with models.DAG(
        "example_gcp_speech",
        default_args=default_args,
        schedule_interval=None  # Override to match your needs
) as dag:

    # [START howto_operator_text_to_speech_synthesize]
    text_to_speech_synthesize_task = GcpTextToSpeechSynthesizeOperator(
        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 = GcpSpeechToTextRecognizeSpeechOperator(
        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