Chirp 3 音声文字変換: 多言語での精度の向上

Chirp 3 は、フィードバックと経験に基づいてユーザーのニーズを満たすように設計された、Google の最新世代の多言語自動音声認識(ASR)専用生成モデルです。Chirp 3 は、以前の Chirp モデルよりも精度と速度が向上しており、ダイアライゼーションと自動言語検出を提供します。

モデルの詳細

Chirp 3: 文字起こしは、Speech-to-Text API V2 でのみ使用できます。

モデル ID

Chirp 3: Transcription は他のモデルと同様に使用できます。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 時間の長い音声に最適) サポート対象

ご利用いただけるリージョン

Chirp 3 は、次の Google Cloud リージョンで利用できます。今後さらに追加される予定です。

Google Cloud ゾーン 提供状況
us(multi-region) 一般提供
eu(multi-region) 一般提供
asia-southeast1 一般提供
asia-northeast1 GA

ここで説明されているように、Location API を使用して、各音声文字変換モデルでサポートされている最新の Google Cloud のリージョン、言語とロケール、機能の一覧を確認できます。

音声文字変換の対応言語

Chirp 3 は、次の言語の StreamingRecognizeRecognizeBatchRecognize で音声文字変換をサポートしています。

言語 BCP-47 Code リリース準備
カタルーニャ語(スペイン)ca-ESGA
中国語(簡体字、中国)cmn-Hans-CNGA
クロアチア語(クロアチア)hr-HRGA
デンマーク語(デンマーク)da-DKGA
オランダ語(オランダ)nl-NLGA
英語(オーストラリア)en-AUGA
英語(英国)en-GBGA
英語(インド)en-INGA
日本語en-USGA
フィンランド語(フィンランド)fi-FIGA
フランス語(カナダ)fr-CAGA
フランス語(フランス)fr-FRGA
ドイツ語(ドイツ)de-DEGA
ギリシャ語(ギリシャ)el-GRGA
ヒンディー語(インド)hi-INGA
イタリア語(イタリア)it-ITGA
日本語(日本)ja-JPGA
韓国語(韓国)ko-KRGA
ポーランド語(ポーランド)pl-PLGA
ポルトガル語(ブラジル)pt-BRGA
ポルトガル語(ポルトガル)pt-PTGA
ルーマニア語(ルーマニア)ro-ROGA
ロシア語(ロシア)ru-RUGA
スペイン語(スペイン)es-ESGA
スペイン語(米国)es-USGA
スウェーデン語(スウェーデン)sv-SEGA
トルコ語(トルコ)tr-TRGA
ウクライナ語(ウクライナ)uk-UAGA
ベトナム語(ベトナム)vi-VNGA
アラビア語ar-XAプレビュー
アラビア語(アルジェリア)ar-DZプレビュー
アラビア語(バーレーン)ar-BHプレビュー
アラビア語(エジプト)ar-EGプレビュー
アラビア語(イスラエル)ar-ILプレビュー
アラビア語(ヨルダン)ar-JOプレビュー
アラビア語(クウェート)ar-KWプレビュー
アラビア語(レバノン)ar-LBプレビュー
アラビア語(モーリタニア)ar-MRプレビュー
アラビア語(モロッコ)ar-MAプレビュー
アラビア語(オマーン)ar-OMプレビュー
アラビア語(カタール)ar-QAプレビュー
アラビア語(サウジアラビア)ar-SAプレビュー
アラビア語(パレスチナ国)ar-PSプレビュー
アラビア語(シリア)ar-SYプレビュー
アラビア語(チュニジア)ar-TNプレビュー
アラビア語(アラブ首長国連邦)ar-AEプレビュー
アラビア語(イエメン)ar-YEプレビュー
アルメニア語(アルメニア)hy-AMプレビュー
ベンガル語(バングラデシュ)bn-BDプレビュー
ベンガル語(インド)bn-INプレビュー
ブルガリア語(ブルガリア)bg-BGプレビュー
ビルマ語(ミャンマー)my-MMプレビュー
中央クルド語(イラク)ar-IQプレビュー
広東語(繁体字、香港)yue-Hant-HKプレビュー
中国語(繁体字、台湾)cmn-Hant-TWプレビュー
チェコ語(チェコ共和国)cs-CZプレビュー
英語(フィリピン)en-PHプレビュー
エストニア語(エストニア)et-EEプレビュー
フィリピン語(フィリピン)fil-PHプレビュー
グジャラト語(インド)gu-INプレビュー
ヘブライ語(イスラエル)iw-ILプレビュー
ハンガリー語(ハンガリー)hu-HUプレビュー
インドネシア語(インドネシア)id-IDプレビュー
カンナダ語(インド)kn-INプレビュー
クメール語(カンボジア)km-KHプレビュー
ラオ語(ラオス)lo-LAプレビュー
ラトビア語(ラトビア)lv-LVプレビュー
リトアニア語(リトアニア)lt-LTプレビュー
マレー語(マレーシア)ms-MYプレビュー
マラヤーラム語(インド)ml-INプレビュー
マラーティー語(インド)mr-INプレビュー
ネパール語(ネパール)ne-NPプレビュー
ノルウェー語(ノルウェー)no-NOプレビュー
ペルシャ語(イラン)fa-IRプレビュー
セルビア語(セルビア)sr-RSプレビュー
スロバキア語(スロバキア)sk-SKプレビュー
スロベニア語(スロベニア)sl-SIプレビュー
スペイン語(メキシコ)es-MXプレビュー
スワヒリ語swプレビュー
タミル語(インド)ta-INプレビュー
テルグ語(インド)te-INプレビュー
タイ語(タイ)th-THプレビュー
ウズベク語(ウズベキスタン)uz-UZプレビュー

ダイアライゼーションの対応言語

Chirp 3 は、次の言語の BatchRecognizeRecognize でのみ音声文字変換とダイアライゼーションをサポートしています。

言語 BCP-47 コード
中国語(簡体字、中国) cmn-Hans-CN
ドイツ語(ドイツ) de-DE
英語(英国) en-GB
英語(インド) en-IN
英語(米国) en-US
スペイン語(スペイン) es-ES
スペイン語(米国) es-US
フランス語(カナダ) fr-CA
フランス語(フランス) fr-FR
ヒンディー語(インド) hi-IN
イタリア語(イタリア) it-IT
日本語(日本) ja-JP
韓国語(韓国) ko-KR
ポルトガル語(ブラジル) pt-BR

機能のサポートと制限事項

Chirp 3 は、次の機能をサポートしています。

機能 説明 リリース ステージ
句読点入力の自動化 モデルによって自動的に生成され、必要に応じて無効にできます。 GA
大文字の自動入力 モデルによって自動的に生成され、必要に応じて無効にできます。 GA
発話レベルのタイムスタンプ モデルによって自動的に生成されます。 GA
話者ダイアライゼーション シングル チャンネルの音声サンプル内の複数の話者を自動的に識別します。BatchRecognize でのみご利用いただけます GA
音声適応(バイアス) フレーズや単語の形式でモデルにヒントを提供することで、特定の用語や固有名詞の認識精度を高めることができます。 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/v2/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/v2/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 では、モデル適応を使用して特定の音声の音声文字変換の精度を高めることができます。これにより、特定の単語やフレーズのリストを指定して、モデルがそれらを認識する可能性を高めることができます。これは、分野固有の用語、固有名詞、固有の語彙に特に役立ちます。

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

ノイズ除去機能と SNR フィルタリングを有効にする

Chirp 3 は、バックグラウンド ノイズを低減し、文字起こし前に不要な音をフィルタリングすることで、音声品質を向上させることができます。ノイズの多い環境での結果を改善するには、組み込みのノイズ除去機能と信号対雑音比(SNR)フィルタリングを有効にします。

denoiser_audio=true を設定すると、BGM や雨音、交通騒音などのノイズを効果的に軽減できます。

音声文字変換に必要な音声の最小音量を制御するために snr_threshold=X を設定できます。これにより、話し手以外の音声や周囲の雑音をフィルタして、結果に不要なテキストが表示されないようにすることができます。snr_threshold の値が大きいほど、モデルが発言を文字起こしできるようにするためにユーザーが大きな声で話す必要があります。

SNR フィルタリングは、リアルタイム ストリーミングのユースケースで不要な音声を音声文字変換用のモデルに送信しないようにするために使用できます。この設定値を大きくする場合、音声文字変換モデルに送信される音声の音量はバックグラウンド ノイズに対して相対的に大きくなる必要があります。

snr_threshold の構成は、denoise_audiotruefalse かによって動作が変わります。denoise_audio=true の場合、バックグラウンド ノイズが除去されて音声が比較的クリアになります。音声の全体的な SNR が向上します。

ユースケースに話し手の声のみが含まれ、他の人の声が含まれない場合は、denoise_audio=true を設定して SNR フィルタリングの感度を高めます。これにより、音声以外のノイズをフィルタで除去できます。ユースケースで、バックグラウンドで人が話しているときにバックグラウンドの音声を文字起こししないようにしたい場合は、denoise_audio=false を設定して SNR しきい値を下げることを検討してください。

推奨される SNR しきい値は次のとおりです。妥当な snr_threshold 値は 01000 の範囲で設定できます。値 0 は何もフィルタしないことを意味し、1000 はすべてをフィルタすることを意味します。推奨設定が機能しない場合は、値を微調整します。

音声のノイズ除去 SNR のしきい値 音声の感度
true 10.0
true 20.0
true 40.0
true 100.0 最低
false 0.5
false 1.0
false 2.0
false 5.0 最低

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_with_timestamps(
   audio_file: str
) -> cloud_speech.RecognizeResponse:
   """Transcribes an audio file using the Chirp 3 model of Google Cloud Speech-to-Text v2 API, which provides word-level timestamps for each transcribed word.
   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",
       denoiser_config={
           denoise_audio: True,
           # Medium snr threshold
           snr_threshold: 20.0,
       }
   )

   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

Google Cloud コンソールで Chirp 3 を使用する

  1. Google Cloud アカウントに登録して、プロジェクトを作成します。
  2. Google Cloud コンソールで [Speech] に移動します。
  3. API が有効になっていない場合は、API を有効にします。
  4. STT コンソールのワークスペースがあることを確認します。ワークスペースがない場合は、ワークスペースを作成する必要があります。

    1. [音声文字変換] ページにアクセスし、[新しい音声文字変換] をクリックします。

    2. [ワークスペース] プルダウンを開き、[新しいワークスペース] をクリックして、音声文字変換用のワークスペースを作成します。

    3. [新しいワークスペースの作成] ナビゲーション サイドバーで [参照] をクリックします。

    4. クリックすると新しいバケットが作成されます。

    5. バケットの名前を入力して、[続行] をクリックします。

    6. [作成] をクリックして Cloud Storage バケットを作成します。

    7. バケットが作成されたら、[選択] をクリックして使用するバケットを選択します。

    8. [作成] をクリックして、Speech-to-Text API V2 コンソール用のワークスペースの作成を完了します。

  5. 実際の音声に音声文字変換を行います。

    ファイルの選択またはアップロードを示す音声文字変換の作成ページのスクリーンショット。

    [新しい音声文字変換] ページで、[ローカル アップロード](アップロード)または [Cloud Storage](既存の Cloud Storage ファイルの指定)のいずれかから音声ファイルを選択します。

  6. [続行] をクリックして、[ 音声文字変換のオプション] に移動します。

    1. 以前に作成した認識ツールから、Chirp で認識に使用する音声言語を選択します。

    2. [モデル] プルダウンから、[chirp_3] を選択します。

    3. [認識ツール] プルダウンで、新しく作成した認識ツールを選択します。

    4. [送信] をクリックし、chirp_3 を使用して最初の認識リクエストを実行します。

  7. Chirp 3 の音声文字変換の結果を表示します。

    1. [音声文字変換] ページで、音声文字変換の名前をクリックして結果を表示します。

    2. [Transcription details] ページで、音声文字変換の結果を表示し、必要に応じてブラウザで音声を再生します。

次のステップ