Google Cloud Speech to Text Operator¶
前置任務¶
要使用這些 Operator,您必須完成一些事情
使用 Cloud Console 選擇或建立 Cloud Platform 專案。
為您的專案啟用計費,如 Google Cloud 文件中所述。
啟用 API,如 Cloud Console 文件中所述。
透過 pip 安裝 API 庫。
pip install 'apache-airflow[google]'安裝的詳細資訊可在 安裝 中找到。
CloudSpeechToTextRecognizeSpeechOperator¶
識別音訊輸入中的語音並返回文字。
有關引數定義,請參閱 CloudSpeechToTextRecognizeSpeechOperator
引數¶
config 和 audio 引數需要是 dicts 或來自 google.cloud.speech_v1.types 模組的相應類物件
tests/system/google/cloud/speech_to_text/example_speech_to_text.py
INPUT = {"text": "Sample text for demo purposes"}
VOICE = {"language_code": "en-US", "ssml_gender": "FEMALE"}
AUDIO_CONFIG = {"audio_encoding": "LINEAR16"}
filename 是一個簡單的字串引數
tests/system/google/cloud/speech_to_text/example_speech_to_text.py
CONFIG = RecognitionConfig({"encoding": "LINEAR16", "language_code": "en_US"})
AUDIO = RecognitionAudio({"uri": f"gs://{BUCKET_NAME}/{FILE_NAME}"})
使用 Operator¶
tests/system/google/cloud/speech_to_text/example_speech_to_text.py
speech_to_text_recognize_task = CloudSpeechToTextRecognizeSpeechOperator(
config=CONFIG, audio=AUDIO, task_id="speech_to_text_recognize_task"
)
模板化¶
template_fields: Sequence[str] = (
"audio",
"config",
"project_id",
"gcp_conn_id",
"timeout",
"impersonation_chain",
)
參考¶
更多資訊,請參閱