Google Cloud Speech to Text 運算子

先決條件任務

若要使用這些運算子,您必須完成以下幾件事

CloudSpeechToTextRecognizeSpeechOperator

辨識音訊輸入中的語音並傳回文字。

如需參數定義,請查看 CloudSpeechToTextRecognizeSpeechOperator

引數

config 和 audio 引數需要是字典或 google.cloud.speech_v1.types 模組中對應類別的物件

如需更多資訊,請參閱:https://googleapis.github.io/google-cloud-python/latest/speech/gapic/v1/api.html#google.cloud.speech_v1.SpeechClient.recognize

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}"})

使用運算子

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",
)

參考

如需更多資訊,請查看

此條目是否有幫助?