Chirp 3 הוא הדור האחרון של המודלים הגנרטיביים של Google לזיהוי דיבור אוטומטי (ASR) בכמה שפות. הוא נועד לענות על צורכי המשתמשים על סמך משוב וניסיון. Chirp 3 מספק דיוק ומהירות משופרים בהשוואה למודלים קודמים של Chirp, ומספק דיאריזציה וזיהוי שפה אוטומטי.
פרטי המודל
Chirp 3: Transcription זמין רק בגרסה 2 של Speech-to-Text API.
מזהי הדגמים
אתם יכולים להשתמש ב-Chirp 3: Transcription כמו בכל מודל אחר. פשוט מציינים את מזהה המודל המתאים בבקשת הזיהוי כשמשתמשים ב-API, או את שם המודל כשמשתמשים במסוף Google Cloud . ציינו את המזהה המתאים בבקשת הזיהוי.
| דגם | מזהה הדגם |
|---|---|
| Chirp 3 | chirp_3 |
שיטות API
לא כל שיטות הזיהוי תומכות באותן קבוצות של שפות זמינות. מכיוון ש-Chirp 3 זמין ב-Speech-to-Text API V2, הוא תומך בשיטות הזיהוי הבאות:
| גרסת ה-API | שיטת ה-API | תמיכה |
|---|---|---|
| V2 | Speech.StreamingRecognize (מתאים לסטרימינג ולאודיו בזמן אמת) | נתמך |
| V2 | Speech.Recognize (מתאים לאודיו קצר מדקה) | נתמך |
| V2 | Speech.BatchRecognize (מתאים לקטעי אודיו ארוכים, בדרך כלל מדקה אחת עד שעה, אבל עד 20 דקות אם מפעילים חותמות זמן ברמת המילה) | נתמך |
זמינות אזורית
המודל chirp_3 דורש נקודת קצה אזורית או מרובת-אזורים ל-API, כמו us-speech.googleapis.com. היא לא זמינה בנקודת הקצה (endpoint) של 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 |
| שימוש אוטומטי באותיות רישיות | המודל יוצר אותן באופן אוטומטי, ואפשר להשבית אותן. | 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,000 ביטויים בסך הכול בכל המשאבים של
PhraseSetשמופיעים בשורה או שיש אליהם הפניה. אם תחרגו מ-1,000 ביטויים, תוחזר השגיאהINVALID_ARGUMENT. - Chirp 3 מתעלם מערכים מספריים של
boostברשומותPhraseSetו-Phrase(אם הם צוינו, הערכים עדיין צריכים להיות בטווח החוקי של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 יכול להפחית את רעשי הרקע במהלך תמלול סטרימינג כשמגדירים את denoiser_config ב-RecognitionConfig:
- מגדירים את
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: אופטימיזציה לביטויים קצרים, כמו משפטים בודדים או פקודות, למשל "תזכיר לי להתקשר לרופא השיניים מחר". ההגדרה הזו מקצרת את זמן ההמתנה אחרי זיהוי הדיבור, וכך מספקת תגובה מהירה יותר מההגדרה הרגילה תוך שמירה על דיוק סביר ברמת המשפט.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()
שימוש ב-Chirp 3 במסוף Google Cloud
- נרשמים לחשבון Google Cloud ויוצרים פרויקט.
- נכנסים לדף Speech במסוף Google Cloud .
- אם ה-API לא מופעל, מפעילים אותו.
מוודאים שיש לכם סביבת עבודה במסוף STT. אם אין לכם סביבת עבודה, אתם צריכים ליצור אחת.
עוברים אל דף התמלילים ולוחצים על תמליל חדש.
פותחים את התפריט הנפתח Workspace ולוחצים על New Workspace כדי ליצור סביבת עבודה לתמלול.
בסרגל הצד של הניווט Create a new workspace, לוחצים על Browse.
לוחצים כדי ליצור קטגוריה חדשה.
נותנים שם לקטגוריה ולוחצים על Continue.
לוחצים על Create כדי ליצור את הקטגוריה של Cloud Storage.
אחרי שיוצרים את הקטגוריה, לוחצים על Select כדי לבחור את הקטגוריה לשימוש.
לוחצים על Create כדי לסיים את יצירת סביבת העבודה במסוף Speech-to-Text API V2.
תמלול של האודיו בפועל.
הדף ליצירת תמליל ב-Speech-to-Text, שבו בוחרים או מעלים קובץ. בדף New Transcription, בוחרים את קובץ האודיו באמצעות העלאה (Local upload) או מציינים קובץ קיים ב-Cloud Storage (Cloud storage).
לוחצים על המשך כדי לעבור אל אפשרויות התמלול.
בוחרים את השפה המדוברת שבה רוצים להשתמש לזיהוי באמצעות Chirp מהמזהה שיצרתם קודם.
בתפריט הנפתח של המודל, בוחרים באפשרות chirp_3.
בתפריט הנפתח Recognizer, בוחרים את המזהה החדש שיצרתם.
לוחצים על Submit כדי להריץ את בקשת הזיהוי הראשונה באמצעות
chirp_3.
צפייה בתוצאת התמלול של Chirp 3.
בדף תמלילים, לוחצים על שם התמליל כדי לראות את התוצאה שלו.
בדף Transcription details, בודקים את תוצאת התמלול, ואם רוצים, מפעילים את האודיו בדפדפן.