Chirp 3 は、フィードバックと経験に基づいてユーザーのニーズを満たすように設計された、Google の最新世代の多言語自動音声認識(ASR)専用生成モデルです。Chirp 3 は、以前の Chirp モデルよりも精度と速度が向上しており、ダイアライゼーションと自動言語検出が可能です。
モデルの詳細
Chirp 3: 音声文字変換は、Speech-to-Text API V2 でのみ使用できます。
モデル ID
Chirp 3: 音声文字変換は他のモデルと同様に使用できます。API を使用する場合は認識リクエストで適切なモデル ID を指定します。 Google Cloud コンソールではモデル名を指定します。認識で適切な識別子を指定します。
| モデル | モデル ID |
|---|---|
| Chirp 3 | chirp_3 |
API メソッド
Chirp 3 は Speech-to-Text API V2 で使用できるため、次の認識方法がサポートされています。ただし、すべての認識方法で同じ言語のアベイラビリティ セットがサポートされているわけではありません。
| API のバージョン | API メソッド | サポート |
|---|---|---|
| V2 | Speech.StreamingRecognize(ストリーミングとリアルタイム音声に最適) | サポートされている |
| V2 | Speech.Recognize(1 分未満の音声に最適) | サポートされている |
| V2 | Speech.BatchRecognize(1 分~ 1 時間の長い音声に最適。ただし、単語レベルのタイムスタンプが有効になっている場合は最大 20 分) | サポート対象 |
ご利用いただけるリージョン
chirp_3 モデルには、us-speech.googleapis.com などのリージョンまたはマルチリージョン API エンドポイントが必要です。global エンドポイントでは使用できません。
サポートされているロケーション、言語 / 地域、機能については、Cloud Speech-to-Text V2 でサポートされている言語をご覧ください。chirp_3 でフィルタします。リージョン別の提供状況の説明に従って、Locations API をクエリすることもできます。
音声文字変換の対応言語
Chirp 3 は、StreamingRecognize、Recognize、BatchRecognize で音声文字変換をサポートしています。現在サポートされている言語のリストについては、Cloud Speech-to-Text V2 でサポートされている言語をご覧ください。chirp_3 モデルでフィルタします。機能ごとのリリース ステージについては、リージョン別の提供状況の説明に従って Locations API にクエリを実行します。
ダイアライゼーションの対応言語
Chirp 3 は、Recognize と BatchRecognize で話者ダイアライゼーションをサポートしていますが、StreamingRecognize ではサポートしていません。ダイアライゼーションは、話されている言語がダイアライゼーションをサポートしている場合、auto 言語検出でも機能します。サポートされている言語 / 地域については、Cloud Speech-to-Text V2 でサポートされている言語をご覧ください。
機能のサポートと制限事項
Chirp 3 は、次の機能をサポートしています。
| 機能 | 説明 | リリース ステージ |
|---|---|---|
| 句読点入力の自動化 | モデルによって自動的に生成され、必要に応じて無効にできます。 | 一般提供 |
| 大文字の自動入力 | モデルによって自動的に生成され、必要に応じて無効にできます。 | GA |
| 発話レベルのタイムスタンプ | モデルによって自動的に生成されます。Speech.StreamingRecognize でのみご利用いただけます |
GA |
| 話者ダイアライゼーション | シングル チャンネルの音声サンプル内の複数の話者を自動的に識別します。Speech.Recognize と Speech.BatchRecognize で利用できます。 |
GA |
| 音声適応(バイアス) | プロンプトベースのフレーズヒントを提供することで、特定の用語や固有名詞の認識精度を高めることができます。モデル適応により精度を向上させるをご覧ください。 | GA |
| 単語レベルのタイムスタンプ | 有効にすると、音声文字変換された各単語のタイムスタンプが生成されます。これにより、音声文字変換の精度がわずかに低下する可能性があります。Speech.Recognize と Speech.BatchRecognize で利用可能。Speech.StreamingRecognize ではサポートされていません。 |
GA |
| 言語に依存しない音声文字変換 | 最も一般的な言語で自動的に推測して文字起こしを行います。 | GA |
| カスタム プロンプト | カスタマイズされた音声文字変換のフォーマット指示をモデルに提供します。 | プレビュー |
Chirp 3 は、次の機能をサポートしていません。
| 機能 | 説明 |
|---|---|
| 単語レベルの信頼スコア | API は値を返しますが、正確な信頼スコアではありません。 |
Chirp 3 を使用して音声文字変換を行う
音声文字変換タスクに Chirp 3 を使用する方法を確認します。
音声認識ストリーミングを実施する
Python
import os
from google.cloud.speech_v2 import SpeechClient
from google.cloud.speech_v2.types import cloud_speech
from google.api_core.client_options import ClientOptions
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
REGION = "us"
def transcribe_streaming_chirp3(
audio_file: str
) -> cloud_speech.StreamingRecognizeResponse:
"""Transcribes audio from audio file stream using the Chirp 3 model of Google Cloud Speech-to-Text v2 API.
Args:
audio_file (str): Path to the local audio file to be transcribed.
Example: "resources/audio.wav"
Returns:
cloud_speech.RecognizeResponse: The response from the Speech-to-Text API V2 containing
the transcription results.
"""
# Instantiates a client
client = SpeechClient(
client_options=ClientOptions(
api_endpoint=f"{REGION}-speech.googleapis.com",
)
)
# Reads a file as bytes
with open(audio_file, "rb") as f:
content = f.read()
# In practice, stream should be a generator yielding chunks of audio data
chunk_length = len(content) // 5
stream = [
content[start : start + chunk_length]
for start in range(0, len(content), chunk_length)
]
audio_requests = (
cloud_speech.StreamingRecognizeRequest(audio=audio) for audio in stream
)
recognition_config = cloud_speech.RecognitionConfig(
auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),
language_codes=["en-US"],
model="chirp_3",
)
streaming_config = cloud_speech.StreamingRecognitionConfig(
config=recognition_config
)
config_request = cloud_speech.StreamingRecognizeRequest(
recognizer=f"projects/{PROJECT_ID}/locations/{REGION}/recognizers/_",
streaming_config=streaming_config,
)
def requests(config: cloud_speech.RecognitionConfig, audio: list) -> list:
yield config
yield from audio
# Transcribes the audio into text
responses_iterator = client.streaming_recognize(
requests=requests(config_request, audio_requests)
)
responses = []
for response in responses_iterator:
responses.append(response)
for result in response.results:
print(f"Transcript: {result.alternatives[0].transcript}")
return responses
同期音声認識を行う
Python
import os
from google.cloud.speech_v2 import SpeechClient
from google.cloud.speech_v2.types import cloud_speech
from google.api_core.client_options import ClientOptions
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
REGION = "us"
def transcribe_sync_chirp3(
audio_file: str
) -> cloud_speech.RecognizeResponse:
"""Transcribes an audio file using the Chirp 3 model of Google Cloud Speech-to-Text V2 API.
Args:
audio_file (str): Path to the local audio file to be transcribed.
Example: "resources/audio.wav"
Returns:
cloud_speech.RecognizeResponse: The response from the Speech-to-Text API containing
the transcription results.
"""
# Instantiates a client
client = SpeechClient(
client_options=ClientOptions(
api_endpoint=f"{REGION}-speech.googleapis.com",
)
)
# Reads a file as bytes
with open(audio_file, "rb") as f:
audio_content = f.read()
config = cloud_speech.RecognitionConfig(
auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),
language_codes=["en-US"],
model="chirp_3",
)
request = cloud_speech.RecognizeRequest(
recognizer=f"projects/{PROJECT_ID}/locations/{REGION}/recognizers/_",
config=config,
content=audio_content,
)
# Transcribes the audio into text
response = client.recognize(request=request)
for result in response.results:
print(f"Transcript: {result.alternatives[0].transcript}")
return response
一括音声認識を実行する
Python
import os
from google.cloud.speech_v2 import SpeechClient
from google.cloud.speech_v2.types import cloud_speech
from google.api_core.client_options import ClientOptions
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
REGION = "us"
def transcribe_batch_3(
audio_uri: str,
) -> cloud_speech.BatchRecognizeResults:
"""Transcribes an audio file from a Google Cloud Storage URI using the Chirp 3 model of Google Cloud Speech-to-Text v2 API.
Args:
audio_uri (str): The Google Cloud Storage URI of the input audio file.
E.g., gs://[BUCKET]/[FILE]
Returns:
cloud_speech.RecognizeResponse: The response from the Speech-to-Text API containing
the transcription results.
"""
# Instantiates a client
client = SpeechClient(
client_options=ClientOptions(
api_endpoint=f"{REGION}-speech.googleapis.com",
)
)
config = cloud_speech.RecognitionConfig(
auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),
language_codes=["en-US"],
model="chirp_3",
)
file_metadata = cloud_speech.BatchRecognizeFileMetadata(uri=audio_uri)
request = cloud_speech.BatchRecognizeRequest(
recognizer=f"projects/{PROJECT_ID}/locations/{REGION}/recognizers/_",
config=config,
files=[file_metadata],
recognition_output_config=cloud_speech.RecognitionOutputConfig(
inline_response_config=cloud_speech.InlineOutputConfig(),
),
)
# Transcribes the audio into text
operation = client.batch_recognize(request=request)
print("Waiting for operation to complete...")
response = operation.result(timeout=120)
for result in response.results[audio_uri].transcript.results:
print(f"Transcript: {result.alternatives[0].transcript}")
return response.results[audio_uri].transcript
Chirp 3 機能を使用する
最新機能の使用方法とそのコード例です。
言語に依存しない音声文字変換を行う
Chirp 3 は、音声で話されている主要な言語を自動的に識別して文字変換できます。これは、多言語アプリケーションに不可欠です。これを実現するには、コード例に示すように language_codes=["auto"] を設定します。
Python
import os
from google.cloud.speech_v2 import SpeechClient
from google.cloud.speech_v2.types import cloud_speech
from google.api_core.client_options import ClientOptions
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
REGION = "us"
def transcribe_sync_chirp3_auto_detect_language(
audio_file: str
) -> cloud_speech.RecognizeResponse:
"""Transcribes an audio file and auto-detect spoken language using Chirp 3.
Please see https://cloud.google.com/speech-to-text/docs/encoding for more
information on which audio encodings are supported.
Args:
audio_file (str): Path to the local audio file to be transcribed.
Example: "resources/audio.wav"
Returns:
cloud_speech.RecognizeResponse: The response from the Speech-to-Text API containing
the transcription results.
"""
# Instantiates a client
client = SpeechClient(
client_options=ClientOptions(
api_endpoint=f"{REGION}-speech.googleapis.com",
)
)
# Reads a file as bytes
with open(audio_file, "rb") as f:
audio_content = f.read()
config = cloud_speech.RecognitionConfig(
auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),
language_codes=["auto"], # Set language code to auto to detect language.
model="chirp_3",
)
request = cloud_speech.RecognizeRequest(
recognizer=f"projects/{PROJECT_ID}/locations/{REGION}/recognizers/_",
config=config,
content=audio_content,
)
# Transcribes the audio into text
response = client.recognize(request=request)
for result in response.results:
print(f"Transcript: {result.alternatives[0].transcript}")
print(f"Detected Language: {result.language_code}")
return response
言語制限付きの音声文字変換を行う
Chirp 3 は、音声ファイル内の主要な言語を自動的に特定して文字起こしできます。また、["en-US", "fr-FR"] のように、想定される特定のロケールに基づいて条件を設定することもできます。これにより、コード例に示すように、モデルのリソースが最も可能性の高い言語に集中し、より信頼性の高い結果が得られます。
Python
import os
from google.cloud.speech_v2 import SpeechClient
from google.cloud.speech_v2.types import cloud_speech
from google.api_core.client_options import ClientOptions
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
REGION = "us"
def transcribe_sync_3_auto_detect_language(
audio_file: str
) -> cloud_speech.RecognizeResponse:
"""Transcribes an audio file and auto-detect spoken language using Chirp 3.
Please see https://cloud.google.com/speech-to-text/docs/encoding for more
information on which audio encodings are supported.
Args:
audio_file (str): Path to the local audio file to be transcribed.
Example: "resources/audio.wav"
Returns:
cloud_speech.RecognizeResponse: The response from the Speech-to-Text API containing
the transcription results.
"""
# Instantiates a client
client = SpeechClient(
client_options=ClientOptions(
api_endpoint=f"{REGION}-speech.googleapis.com",
)
)
# Reads a file as bytes
with open(audio_file, "rb") as f:
audio_content = f.read()
config = cloud_speech.RecognitionConfig(
auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),
language_codes=["en-US", "fr-FR"], # Set language codes of the expected spoken locales
model="chirp_3",
)
request = cloud_speech.RecognizeRequest(
recognizer=f"projects/{PROJECT_ID}/locations/{REGION}/recognizers/_",
config=config,
content=audio_content,
)
# Transcribes the audio into text
response = client.recognize(request=request)
for result in response.results:
print(f"Transcript: {result.alternatives[0].transcript}")
print(f"Detected Language: {result.language_code}")
return response
音声文字変換と話者ダイアライゼーションを行う
音声文字変換とダイアライゼーションのタスクに Chirp 3 を使用します。
Python
import os
from google.cloud.speech_v2 import SpeechClient
from google.cloud.speech_v2.types import cloud_speech
from google.api_core.client_options import ClientOptions
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
REGION = "us"
def transcribe_batch_chirp3(
audio_uri: str,
) -> cloud_speech.BatchRecognizeResults:
"""Transcribes an audio file from a Google Cloud Storage URI using the Chirp 3 model of Google Cloud Speech-to-Text V2 API.
Args:
audio_uri (str): The Google Cloud Storage URI of the input
audio file. E.g., gs://[BUCKET]/[FILE]
Returns:
cloud_speech.RecognizeResponse: The response from the
Speech-to-Text API containing the transcription results.
"""
# Instantiates a client.
client = SpeechClient(
client_options=ClientOptions(
api_endpoint=f"{REGION}-speech.googleapis.com",
)
)
config = cloud_speech.RecognitionConfig(
auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),
language_codes=["en-US"], # Use "auto" to detect language.
model="chirp_3",
features=cloud_speech.RecognitionFeatures(
# Enable diarization by setting empty diarization configuration.
diarization_config=cloud_speech.SpeakerDiarizationConfig(),
),
)
file_metadata = cloud_speech.BatchRecognizeFileMetadata(uri=audio_uri)
request = cloud_speech.BatchRecognizeRequest(
recognizer=f"projects/{PROJECT_ID}/locations/{REGION}/recognizers/_",
config=config,
files=[file_metadata],
recognition_output_config=cloud_speech.RecognitionOutputConfig(
inline_response_config=cloud_speech.InlineOutputConfig(),
),
)
# Creates audio transcription job.
operation = client.batch_recognize(request=request)
print("Waiting for transcription job to complete...")
response = operation.result(timeout=120)
for result in response.results[audio_uri].transcript.results:
print(f"Transcript: {result.alternatives[0].transcript}")
print(f"Detected Language: {result.language_code}")
print(f"Speakers per word: {result.alternatives[0].words}")
return response.results[audio_uri].transcript
モデル適応により精度を向上させる
Chirp 3 は、PhraseSet リソースを使用したモデル適応をサポートしており、ドメイン固有の用語、固有名詞、頭字語の認識を改善できます。
Chirp 3 はモデル プロンプトを介して適応フレーズを適用するため、次の制約が適用されます。
- 1 つのリクエストには、すべてのインライン リソースと
参照される
PhraseSetリソース全体で最大 1,000 個のフレーズを含めることができます。1,000 フレーズを超えると、INVALID_ARGUMENTエラーが返されます。 - Chirp 3 は、
PhraseSetエントリとPhraseエントリの数値boost値を無視します(指定する場合、値は有効な0~20の範囲内である必要があります)。 ターゲットが設定されていない大規模な
PhraseSetリストを使用すると、一般的な精度が低下し、無音やノイズの発生時に意図しない音声文字変換が増加する可能性があります。リストには、音声に登場する珍しい用語のみを含めるようにしてください。
Python
import os
from google.cloud.speech_v2 import SpeechClient
from google.cloud.speech_v2.types import cloud_speech
from google.api_core.client_options import ClientOptions
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
REGION = "us"
def transcribe_sync_chirp3_model_adaptation(
audio_file: str
) -> cloud_speech.RecognizeResponse:
"""Transcribes an audio file using the Chirp 3 model with adaptation, improving accuracy for specific audio characteristics or vocabulary.
Args:
audio_file (str): Path to the local audio file to be transcribed.
Example: "resources/audio.wav"
Returns:
cloud_speech.RecognizeResponse: The response from the Speech-to-Text API containing
the transcription results.
"""
# Instantiates a client
client = SpeechClient(
client_options=ClientOptions(
api_endpoint=f"{REGION}-speech.googleapis.com",
)
)
# Reads a file as bytes
with open(audio_file, "rb") as f:
audio_content = f.read()
config = cloud_speech.RecognitionConfig(
auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),
language_codes=["en-US"],
model="chirp_3",
# Use model adaptation
adaptation=cloud_speech.SpeechAdaptation(
phrase_sets=[
cloud_speech.SpeechAdaptation.AdaptationPhraseSet(
inline_phrase_set=cloud_speech.PhraseSet(phrases=[
{
"value": "alphabet",
},
{
"value": "cell phone service",
}
])
)
]
)
)
request = cloud_speech.RecognizeRequest(
recognizer=f"projects/{PROJECT_ID}/locations/{REGION}/recognizers/_",
config=config,
content=audio_content,
)
# Transcribes the audio into text
response = client.recognize(request=request)
for result in response.results:
print(f"Transcript: {result.alternatives[0].transcript}")
return response
カスタム プロンプトを使用して音声文字変換の形式を設定する
Chirp 3 は、モデルへのフォーマット指示としてカスタム プロンプトを受け入れます。
Python
import os
from google.cloud.speech_v2 import SpeechClient
from google.cloud.speech_v2.types import cloud_speech
from google.api_core.client_options import ClientOptions
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
REGION = "us"
def transcribe_sync_chirp3_custom_prompt(
audio_file: str,
custom_prompt: str,
) -> cloud_speech.RecognizeResponse:
"""Transcribes an audio file and auto-detect spoken language using Chirp 3.
Args:
audio_file (str): Path to the local audio file to be transcribed.
Example: "resources/audio.wav"
custom_prompt: the customized formatting instructions.
Example: "Capitalize the following special words: GOOGLE, CHIRP."
Example: "For dates don't use the 'December 23rd, 1939' format!
But strictly use the '12/23/1939' format."
Returns:
cloud_speech.RecognizeResponse: The response from the Speech-to-Text API containing
the transcription results.
"""
# Instantiates a client
client = SpeechClient(
client_options=ClientOptions(
api_endpoint=f"{REGION}-speech.googleapis.com",
)
)
# Reads a file as bytes
with open(audio_file, "rb") as f:
audio_content = f.read()
config = cloud_speech.RecognitionConfig(
auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),
language_codes=["en-US"],
model="chirp_3",
features=cloud_speech.RecognitionFeatures(
custom_prompt_config=cloud_speech.CustomPromptConfig(
custom_prompt= custom_prompt,
)
),
)
request = cloud_speech.RecognizeRequest(
recognizer=f"projects/{PROJECT_ID}/locations/{REGION}/recognizers/_",
config=config,
content=audio_content,
)
# Transcribes the audio into text
response = client.recognize(request=request)
print(f"Prompt used: {response.metadata.prompt}")
for result in response.results:
print(f"Transcript: {result.alternatives[0].transcript}")
print(f"Detected Language: {result.language_code}")
return response
ノイズ除去機能を有効にする
Chirp 3 は、RecognitionConfig で denoiser_config を構成すると、ストリーミング音声文字変換中のバックグラウンド ノイズを低減できます。
denoise_audio=trueを設定すると、音楽、雨、交通などの音声以外のバックグラウンド ノイズを軽減できます。snr_thresholdを0.0より大きい値に設定して、信号対雑音比が低い音声セグメントをスキップします。値を0.0に設定すると、しきい値フィルタリングが無効になります。
Python
import os
from google.api_core.client_options import ClientOptions
from google.cloud.speech_v2 import SpeechClient
from google.cloud.speech_v2.types import cloud_speech
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
REGION = "us"
def transcribe_streaming_chirp3_denoiser(
audio_file: str,
) -> list[cloud_speech.StreamingRecognizeResponse]:
"""Streams an audio file to Chirp 3 with the denoiser enabled."""
client = SpeechClient(
client_options=ClientOptions(
api_endpoint=f"{REGION}-speech.googleapis.com",
)
)
recognition_config = cloud_speech.RecognitionConfig(
auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),
language_codes=["en-US"],
model="chirp_3",
denoiser_config=cloud_speech.DenoiserConfig(
denoise_audio=True,
snr_threshold=0.0,
),
)
config_request = cloud_speech.StreamingRecognizeRequest(
recognizer=f"projects/{PROJECT_ID}/locations/{REGION}/recognizers/_",
streaming_config=cloud_speech.StreamingRecognitionConfig(
config=recognition_config,
),
)
def requests():
yield config_request
with open(audio_file, "rb") as f:
while chunk := f.read(4096):
yield cloud_speech.StreamingRecognizeRequest(audio=chunk)
responses_iterator = client.streaming_recognize(requests=requests())
responses = []
for response in responses_iterator:
responses.append(response)
for result in response.results:
if result.is_final:
print(f"Transcript: {result.alternatives[0].transcript}")
return responses
エンドポイントの感度を調整する
Cloud Speech-to-Text API を使用すると、Chirp 3 のストリーミング アプリケーションとリアルタイム アプリケーションのレイテンシと精度のトレードオフを制御できます。デフォルトでは、認識モデルは、音声が検出された後、ユーザーが完全な文またはフレーズを終了したことを確認するために、短い無音時間を待ちます。これにより、最高の精度が確保されますが、最終的なレスポンスにわずかな遅延が発生します。
endpointing_sensitivity は、音声コマンドや音声ボットなどの時間制約のあるアプリケーションで、結果をより迅速に確定するように調整できます。
機密レベル
エンドポイントの感度は、ユースケースに応じて次のいずれかのレベルに構成できます。
ENDPOINTING_SENSITIVITY_STANDARD(デフォルト): レイテンシと精度のバランスを取る標準設定。長い形式のディクテーションや自然な会話など、ほとんどのユースケースに最適化されています。モデルは、結果を確定する前に、発話が完了するまで待機します。ENDPOINTING_SENSITIVITY_SHORT: 「明日、歯医者に電話するよううっかりアラートして」など、1 つの文やコマンドなどの短い発話に最適化されています。この設定により、音声が検出された後の待機時間が短縮されます。これにより、標準設定よりも迅速なレスポンスが得られ、文レベルの精度が維持されます。ENDPOINTING_SENSITIVITY_SUPERSHORT: 「はい」、「いいえ」、「停止」などの非常に短いコマンドや単一の単語に最適化されています。この設定では、レイテンシが最も低くなり、音声の終了が検出されるとすぐに結果が確定します。速度が重要で、発話が短いと予想されるアプリケーションにのみおすすめします。
Python
import time
from google.api_core.client_options import ClientOptions
from google.cloud import speech_v2
RATE = 16000
def transcribe_streaming(
project_id: str,
audio_file: str,
# 'us' is a multi-region that currently supports the 'chirp_3' model.
# Other valid regions include 'eu' or specific regions like 'asia-southeast1'.
region: str = "us"
):
recognizer_path = f"projects/{project_id}/locations/{region}/recognizers/_"
# Setup client with the correct regional endpoint
client = speech_v2.SpeechClient(
client_options=ClientOptions(
api_endpoint=f"{region}-speech.googleapis.com",
quota_project_id=project_id
)
)
recognition_config_obj = speech_v2.RecognitionConfig(
explicit_decoding_config=speech_v2.ExplicitDecodingConfig(
encoding=speech_v2.ExplicitDecodingConfig.AudioEncoding.LINEAR16,
sample_rate_hertz=RATE,
audio_channel_count=1,
),
language_codes=["en-US"],
model="chirp_3",
features=speech_v2.RecognitionFeatures(
enable_automatic_punctuation=True,
),
)
config_request = speech_v2.StreamingRecognizeRequest(
recognizer=recognizer_path,
streaming_config=speech_v2.StreamingRecognitionConfig(
config=recognition_config_obj,
streaming_features=speech_v2.StreamingRecognitionFeatures(
interim_results=False,
enable_voice_activity_events=True,
# Set sensitivity to SUPERSHORT (Low Latency)
endpointing_sensitivity=speech_v2.StreamingRecognitionFeatures.EndpointingSensitivity.ENDPOINTING_SENSITIVITY_SUPERSHORT,
),
)
)
def request_generator():
yield config_request
with open(audio_file, "rb") as f:
while chunk := f.read(4096):
yield speech_v2.StreamingRecognizeRequest(audio=chunk)
start_time = time.time()
print(f"Streaming audio to {region}-speech.googleapis.com...")
for response in client.streaming_recognize(requests=request_generator()):
if response.results:
for result in response.results:
if result.is_final:
print(f"Transcript: {result.alternatives[0].transcript}")
print(f"Time taken: {time.time() - start_time:.3f}s")
def main() -> None:
# TODO: Replace with your Project ID and File Path
PROJECT_ID = "your-project-id"
AUDIO_FILE_PATH = "path/to/your/audio.wav"
transcribe_streaming(
project_id=PROJECT_ID,
audio_file=AUDIO_FILE_PATH
)
if __name__ == "__main__":
main()
Google Cloud コンソールで Chirp 3 を使用する
- Google Cloud アカウントに登録して、プロジェクトを作成します。
- Google Cloud コンソールで [Speech] に移動します。
- API が有効になっていない場合は、API を有効にします。
STT コンソールのワークスペースがあることを確認します。ワークスペースがない場合は、ワークスペースを作成する必要があります。
[音声文字変換] ページにアクセスし、[新しい音声文字変換] をクリックします。
[ワークスペース] プルダウンを開き、[新しいワークスペース] をクリックして、音声文字変換用のワークスペースを作成します。
[新しいワークスペースの作成] ナビゲーション サイドバーで [参照] をクリックします。
クリックすると新しいバケットが作成されます。
バケットの名前を入力して、[続行] をクリックします。
[作成] をクリックして Cloud Storage バケットを作成します。
バケットが作成されたら、[選択] をクリックして使用するバケットを選択します。
[作成] をクリックして、Speech-to-Text API V2 コンソール用のワークスペースの作成を完了します。
実際の音声に音声文字変換を行います。

ファイルの選択またはアップロードを行う音声文字変換の作成ページ。 [新しい音声文字変換] ページで、[ローカル アップロード](アップロード)または [Cloud Storage](既存の Cloud Storage ファイルの指定)のいずれかから音声ファイルを選択します。
[続行] をクリックして、[ 音声文字変換のオプション] に移動します。
以前に作成した認識ツールから、Chirp で認識に使用する音声言語を選択します。
[モデル] プルダウンから、[chirp_3] を選択します。
[認識ツール] プルダウンで、新しく作成した認識ツールを選択します。
[送信] をクリックし、
chirp_3を使用して最初の認識リクエストを実行します。
Chirp 3 の音声文字変換の結果を表示します。
[音声文字変換] ページで、音声文字変換の名前をクリックして結果を表示します。
[音声文字変換の詳細] ページで、音声文字変換の結果を表示し、必要に応じてブラウザで音声を再生します。