שיפור תוצאות התמלול באמצעות התאמת המודל

סקירה כללית

אתם יכולים להשתמש בתכונה התאמת המודל כדי לעזור לטכנולוגיית הדיבור לטקסט (STT) לזהות מילים או ביטויים ספציפיים בתדירות גבוהה יותר מאשר אפשרויות אחרות שאולי יוצעו. לדוגמה, נניח שנתוני האודיו שלכם כוללים לעיתים קרובות את המילה "weather" (מזג אוויר). כשממירים דיבור לטקסט ונתקלים במילה "weather", רוצים שהמילה הזו תתועתק כ-"weather" ולא כ-"whether". במקרה כזה, תוכלו להשתמש בהתאמת המודל כדי להטות את Speech-to-Text לזיהוי המילה "weather".

התאמת המודל מועילה במיוחד בתרחישי השימוש הבאים:

  • שיפור הדיוק של מילים וביטויים שמופיעים לעיתים קרובות בנתוני האודיו. לדוגמה, אפשר להגדיר התראות במודל הזיהוי לגבי פקודות קוליות שבדרך כלל נאמרות על ידי המשתמשים.

    • הרחבת אוצר המילים שזוהה על ידי המרת דיבור לטקסט. המרת דיבור לטקסט כוללת אוצר מילים גדול מאוד. עם זאת, אם נתוני האודיו שלכם כוללים לעיתים קרובות מילים נדירות בשימוש בשפה הכללית (כמו שמות פרטיים או מילים ספציפיות לתחום), אתם יכולים להוסיף אותן באמצעות התאמת מודל.

    • שיפור הדיוק של תמלול הדיבור כשהאודיו שסופק מכיל רעשים או לא ברור במיוחד.

אפשר גם לכוונן את ההטיה של מודל הזיהוי באמצעות התכונה "שיפור התאמת המודל".

שיפור הזיהוי של מילים וביטויים

כדי להגדיל את הסיכוי שהמילה weather תזוהה על ידי Speech-to-Text כשהוא מתמלל את נתוני האודיו, אפשר להעביר את המילה weather באובייקט PhraseSet במשאב SpeechAdaptation.

כשמספקים ביטוי שמורכב מכמה מילים, יש סיכוי גבוה יותר שהמרת דיבור לטקסט (STT) תזהה את המילים האלה ברצף. אם מספקים ביטוי, גדל הסיכוי לזיהוי חלקים מהביטוי, כולל מילים בודדות. בדף המגבלות על תוכן מפורטות המגבלות על מספר הביטויים האלה ועל הגודל שלהם.

שיפור הזיהוי באמצעות מחלקות

מחלקות מייצגות מושגים נפוצים שמופיעים בשפה טבעית, כמו יחידות כספיות ותאריכים ביומן. מחלקות עוזרות לשפר את הדיוק של התמלול לקבוצות גדולות של מילים שמתייחסות למושג משותף, אבל לא תמיד כוללות מילים או ביטויים זהים.

לדוגמה, נניח שנתוני האודיו כוללים הקלטות של אנשים שאומרים את כתובת הרחוב שלהם. יכול להיות שיש לכם הקלטת אודיו של מישהו שאומר "הבית שלי נמצא ברחוב הראשי 123, הבית הרביעי משמאל". במקרה הזה, רוצים ש-Speech-to-Text יזהה את הרצף הראשון של הספרות (123) ככתובת ולא כמספר סידורי (one-hundred twenty-third). אבל לא כל האנשים גרים ברחוב הראשי מספר 123. אי אפשר לפרט כל כתובת רחוב אפשרית במשאב PhraseSet. במקום זאת, אפשר להשתמש במחלקה כדי לציין שמערכת Speech-to-Text צריכה לזהות מספר רחוב בלי קשר למספר עצמו. בדוגמה הזו, מערכת Speech-to-Text תוכל לתמלל בצורה מדויקת יותר ביטויים כמו '123 Main Street' ו-'987 Grand Boulevard' כי שניהם מזוהים כמספרי כתובות.

טוקנים של כיתות

כדי להשתמש בכיתה בהתאמת מודל, צריך לכלול אסימון כיתה בשדה phrases של משאב PhraseSet. כדי לראות אילו טוקנים זמינים בשפה שלכם, אפשר לעיין ברשימת הטוקנים הנתמכים של מחלקות. לדוגמה, כדי לשפר את התמלול של מספרי כתובות מקובץ האודיו, צריך לספק את הערך $ADDRESSNUM בתוך ביטוי ב-PhraseSet.

אפשר להשתמש במחלקות כפריטים עצמאיים במערך phrases או להטמיע אסימון אחד או יותר של מחלקה בביטויים ארוכים יותר של כמה מילים. לדוגמה, אפשר לציין מספר של כתובת בתוך ביטוי ארוך יותר על ידי הכללת טוקן המחלקה במחרוזת: ["my address is $ADDRESSNUM"]. עם זאת, הביטוי הזה לא יעזור במקרים שבהם האודיו מכיל ביטוי דומה אבל לא זהה, כמו "I am at 123 Main Street". כדי לעזור בזיהוי של ביטויים דומים, חשוב להוסיף גם את טוקן הסיווג לבד: ["my address is $ADDRESSNUM", "$ADDRESSNUM"]. אם משתמשים בטוקן מחלקה לא תקין או לא חוקי, Speech-to-Text מתעלם מהטוקן בלי להפעיל שגיאה, אבל עדיין משתמש בשאר הביטוי כהקשר.

כיתות בהתאמה אישית

אפשר גם ליצור CustomClass, מחלקה שמורכבת מרשימה מותאמת אישית של פריטים או ערכים קשורים. לדוגמה, אתם רוצים לתמלל נתוני אודיו שסביר להניח שיכללו את השם של אחת מכמה מאות מסעדות אזוריות. שמות של מסעדות הם יחסית נדירים בדיבור באופן כללי, ולכן יש סיכוי נמוך יותר שהמודל לזיהוי דיבור יבחר אותם כתשובה 'הנכונה'. אתם יכולים להטות את מודל הזיהוי כך שיזהה נכון את השמות האלה כשהם מופיעים באודיו, באמצעות מחלקה מותאמת אישית.

כדי להשתמש בכיתה מותאמת אישית, יוצרים משאב CustomClass שכולל את שם כל מסעדה כ-ClassItem. הפונקציה של מחלקות בהתאמה אישית פועלת באותו אופן כמו אסימוני המחלקות המוגדרים מראש. phrase יכול לכלול גם אסימונים של סוגים מובנים וגם סוגים בהתאמה אישית.

שיפור התוצאות של התמלול באמצעות משבצות לייצור מזון

כברירת מחדל, התאמת המודל מספקת השפעה קטנה יחסית, במיוחד עבור ביטויים בני מילה אחת. התכונה boost להתאמת המודל מאפשרת להגדיל את ההטיה של מודל הזיהוי על ידי הקצאת משקל רב יותר לביטויים מסוימים. מומלץ להשתמש בהגברת הביצועים אם כל התנאים הבאים מתקיימים:

  1. כבר הטמעתם התאמה של המודל.
  2. אתם רוצים לשנות את עוצמת ההשפעה של התאמת המודל על תוצאות התמלול. כדי לראות אם התכונה 'הגברת המהירות' זמינה בשפה שלכם, אפשר לעיין בדף השפות הנתמכות.

לדוגמה, יש לכם הרבה הקלטות של אנשים ששואלים על 'מחיר הכרטיס לכניסה ליריד המחוזי', והמילה 'יריד' מופיעה בתדירות גבוהה יותר מהמילה 'מחיר'. במקרה כזה, אתם יכולים להשתמש בהתאמת המודל כדי להגדיל את הסבירות שהמודל יזהה גם את "fair" וגם את "fare", על ידי הוספה שלהם כ-phrases במשאב PhraseSet. כך Speech-to-Text יזהה את המילים "fair" ו-"fare" בתדירות גבוהה יותר מאשר, למשל, "hare" או "lair".

עם זאת, המילה 'fair' צריכה להיות מזוהה בתדירות גבוהה יותר מהמילה 'fare', כי היא מופיעה בתדירות גבוהה יותר באודיו. יכול להיות שכבר תמללתם את האודיו באמצעות Speech-to-Text API וגיליתם מספר גבוה של שגיאות בזיהוי המילה הנכונה ("fair"). במקרה כזה, כדאי להשתמש בתכונה הגברת התנועה כדי להקצות ערך גבוה יותר של הגברת התנועה למילה fair מאשר למילה fare. הערך המשוקלל הגבוה יותר שמוקצה ל-"fair" גורם ל-Speech-to-Text API לבחור ב-"fair" בתדירות גבוהה יותר מאשר ב-"fare". בלי ערכי הגברה, מודל הזיהוי יזהה את המילים fair ו-fare בהסתברות שווה.

מידע בסיסי על Boost

כשמשתמשים בהגברה, מקצים ערך משוקלל ל-phrase פריטים במשאב PhraseSet. ה-API של Speech-to-Text מתייחס לערך המשוקלל הזה כשהוא בוחר תמלול אפשרי למילים בנתוני האודיו. ככל שהערך גבוה יותר, כך גדל הסיכוי שהמרת הדיבור לטקסט תבחר במילה או בביטוי הזה מתוך החלופות האפשריות.

אם מקצים ערך של הגדלת החשיפה לביטוי שמורכב מכמה מילים, הגדלת החשיפה חלה על הביטוי כולו בלבד. לדוגמה, אתם רוצים להקצות ערך של הגדלת החשיפה לביטוי "My favorite exhibit at the American Museum of Natural History is the blue whale" (המוצג האהוב עליי במוזיאון האמריקאי להיסטוריה של הטבע הוא הלווייתן הכחול). אם מוסיפים את הביטוי הזה לאובייקט phrase ומקצים לו ערך של הגברה, סביר יותר שהמודל לזיהוי יזהה את הביטוי הזה במלואו, מילה במילה.

אם לא מקבלים את התוצאות הרצויות על ידי הגברת הביצועים של צירוף מילים, מומלץ להוסיף את כל הביגרמות (2 מילים, לפי הסדר) שמרכיבות את הצירוף כפריטי phrase נוספים ולהקצות לכל אחת מהן ערכי הגברה. בהמשך לדוגמה הקודמת, אפשר לבדוק הוספה של עוד ביגרמות ואנדגרמות (יותר משתי מילים), כמו "האהוב עליי", "התערוכה האהובה עליי", "התערוכה האהובה", "התערוכה האהובה עליי במוזיאון האמריקאי לתולדות הטבע", "המוזיאון האמריקאי לתולדות הטבע" ו "לווייתן כחול". כך, יש סיכוי גבוה יותר שמודל ה-STT יזהה ביטויים קשורים באודיו שלכם שמכילים חלקים מהביטוי המקורי שהודגש, אבל לא זהים לו מילה במילה.

הגדרת ערכי הבוסט

ערכי ההגברה חייבים להיות מספר צף גדול מ-0. המגבלה המעשית של ערכי ההגברה היא 20. כדי לקבל את התוצאות הטובות ביותר, כדאי להתנסות בתוצאות התמלול על ידי התאמת ערכי ההגברה למעלה או למטה עד לקבלת תוצאות תמלול מדויקות.

ערכים גבוהים יותר של הגברה יכולים להוביל לפחות תוצאות שליליות שגויות, כלומר מקרים שבהם המילה או הביטוי הופיעו באודיו אבל לא זוהו בצורה נכונה על ידי התכונה 'דיבור לטקסט'. עם זאת, הגברת ההדגשה יכולה גם להגדיל את הסיכוי לתוצאות חיוביות שגויות, כלומר מקרים שבהם המילה או הביטוי מופיעים בתמליל למרות שהם לא נאמרו באודיו.

תרחיש לדוגמה של שימוש בהתאמת מודל

בדוגמה הבאה מוסבר איך להשתמש בהתאמת מודל כדי לתמלל הקלטת אודיו של מישהו שאומר "The word is fare". במקרה הזה, בלי התאמה לדיבור, התכונה 'המרת דיבור לטקסט' מזהה את המילה fair. באמצעות התאמה לדיבור, המרת דיבור לטקסט (STT) יכולה לזהות את המילה fare במקום זאת.

לפני שמתחילים

  1. נכנסים לחשבון Google Cloud . אנחנו ממליצים למשתמשים חדשים ב- Google Cloud ליצור חשבון כדי שיוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Speech-to-Text APIs, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  5. Make sure that you have the following role or roles on the project: Cloud Speech Administrator

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. Click Grant access.
    4. In the New principals field, enter your user identifier. This is typically the email address for a Google Account.

    5. Click Select a role, then search for the role.
    6. To grant additional roles, click Add another role and add each additional role.
    7. Click Save.
  6. Install the Google Cloud CLI.

  7. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  8. To initialize the gcloud CLI, run the following command:

    gcloud init
  9. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  10. Verify that billing is enabled for your Google Cloud project.

  11. Enable the Speech-to-Text APIs, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  12. Make sure that you have the following role or roles on the project: Cloud Speech Administrator

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. Click Grant access.
    4. In the New principals field, enter your user identifier. This is typically the email address for a Google Account.

    5. Click Select a role, then search for the role.
    6. To grant additional roles, click Add another role and add each additional role.
    7. Click Save.
  13. Install the Google Cloud CLI.

  14. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  15. To initialize the gcloud CLI, run the following command:

    gcloud init
  16. בספריות הלקוח אפשר להשתמש ב-Application Default Credentials כדי לעבור בקלות אימות מול Google APIs ולשלוח בקשות לאותם ממשקי API. באמצעות Application Default Credentials, אתם יכולים לבדוק את האפליקציה ברמה המקומית ולפרוס אותה בלי לשנות את הקוד שלה. מידע נוסף זמין במאמר אימות לצורך שימוש בספריות לקוח.

  17. אם אתם משתמשים במעטפת מקומית, צרו פרטי כניסה לאימות מקומי בחשבון המשתמש:

    gcloud auth application-default login

    אם אתם משתמשים ב-Cloud Shell, אתם לא צריכים לעשות את זה.

    אם מוחזרת שגיאת אימות ואתם משתמשים בספק זהויות חיצוני (IdP), ודאו ש נכנסתם ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.

חשוב גם לוודא שהתקנתם את ספריית הלקוח.

שיפור התמלול באמצעות PhraseSet

  1. בדוגמה הבאה נוצר PhraseSet עם הביטוי fare והוא מתווסף כ-inline_phrase_set לבקשת זיהוי:

Python

import os

from google.cloud.speech_v2 import SpeechClient
from google.cloud.speech_v2.types import cloud_speech

PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")


def adaptation_v2_inline_phrase_set(audio_file: str) -> cloud_speech.RecognizeResponse:
    """Enhances speech recognition accuracy using an inline phrase set.
    The inline custom phrase set helps the recognizer produce more accurate transcriptions for specific terms.
    Phrases are given a boost to increase their chances of being recognized correctly.
    Args:
        audio_file (str): Path to the local audio file to be transcribed.
    Returns:
        cloud_speech.RecognizeResponse: The full response object which includes the transcription results.
    """

    # Instantiates a client
    client = SpeechClient()

    # Reads a file as bytes
    with open(audio_file, "rb") as f:
        audio_content = f.read()

    # Build inline phrase set to produce a more accurate transcript
    phrase_set = cloud_speech.PhraseSet(
        phrases=[{"value": "fare", "boost": 10}, {"value": "word", "boost": 20}]
    )
    adaptation = cloud_speech.SpeechAdaptation(
        phrase_sets=[
            cloud_speech.SpeechAdaptation.AdaptationPhraseSet(
                inline_phrase_set=phrase_set
            )
        ]
    )
    config = cloud_speech.RecognitionConfig(
        auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),
        adaptation=adaptation,
        language_codes=["en-US"],
        model="short",
    )

    # Prepare the request which includes specifying the recognizer, configuration, and the audio content
    request = cloud_speech.RecognizeRequest(
        recognizer=f"projects/{PROJECT_ID}/locations/global/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

  1. בדוגמה הזו נוצר משאב PhraseSet עם אותו ביטוי, ואז נעשה בו שימוש בבקשת זיהוי:

Python

import os

from google.cloud.speech_v2 import SpeechClient
from google.cloud.speech_v2.types import cloud_speech

PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")


def adaptation_v2_phrase_set_reference(
    audio_file: str,
    phrase_set_id: str,
) -> cloud_speech.RecognizeResponse:
    """Transcribe audio files using a PhraseSet.
    Args:
        audio_file (str): Path to the local audio file to be transcribed.
        phrase_set_id (str): The unique ID of the PhraseSet to use.
    Returns:
        cloud_speech.RecognizeResponse: The full response object which includes the transcription results.
    """

    # Instantiates a client
    client = SpeechClient()

    # Reads a file as bytes
    with open(audio_file, "rb") as f:
        audio_content = f.read()

    # Creating operation of creating the PhraseSet on the cloud.
    operation = client.create_phrase_set(
        parent=f"projects/{PROJECT_ID}/locations/global",
        phrase_set_id=phrase_set_id,
        phrase_set=cloud_speech.PhraseSet(phrases=[{"value": "fare", "boost": 10}]),
    )
    phrase_set = operation.result()

    # Add a reference of the PhraseSet into the recognition request
    adaptation = cloud_speech.SpeechAdaptation(
        phrase_sets=[
            cloud_speech.SpeechAdaptation.AdaptationPhraseSet(
                phrase_set=phrase_set.name
            )
        ]
    )

    # Automatically detect audio encoding. Use "short" model for short utterances.
    config = cloud_speech.RecognitionConfig(
        auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),
        adaptation=adaptation,
        language_codes=["en-US"],
        model="short",
    )
    #  Prepare the request which includes specifying the recognizer, configuration, and the audio content
    request = cloud_speech.RecognizeRequest(
        recognizer=f"projects/{PROJECT_ID}/locations/global/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

שיפור תוצאות התמלול באמצעות CustomClass

  1. בדוגמה הבאה נוצר CustomClass עם הפריט fare והשם fare. לאחר מכן, הוא מפנה אל CustomClass בתוך inline_phrase_set בבקשת זיהוי:

Python

import os

from google.cloud.speech_v2 import SpeechClient
from google.cloud.speech_v2.types import cloud_speech

PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")


def adaptation_v2_inline_custom_class(
    audio_file: str,
) -> cloud_speech.RecognizeResponse:
    """Transcribe audio file using inline custom class.
    The inline custom class helps the recognizer produce more accurate transcriptions for specific terms.
    Args:
        audio_file (str): Path to the local audio file to be transcribed.
    Returns:
        cloud_speech.RecognizeResponse: The response object which includes the transcription results.
    """
    # Instantiates a client
    client = SpeechClient()

    # Reads a file as bytes
    with open(audio_file, "rb") as f:
        audio_content = f.read()

    # Define an inline custom class to enhance recognition accuracy with specific items like "fare" etc.
    custom_class_name = "your-class-name"
    custom_class = cloud_speech.CustomClass(
        name=custom_class_name,
        items=[{"value": "fare"}],
    )

    # Build inline phrase set to produce a more accurate transcript
    phrase_set = cloud_speech.PhraseSet(
        phrases=[{"value": custom_class_name, "boost": 20}]
    )
    adaptation = cloud_speech.SpeechAdaptation(
        phrase_sets=[
            cloud_speech.SpeechAdaptation.AdaptationPhraseSet(
                inline_phrase_set=phrase_set
            )
        ],
        custom_classes=[custom_class],
    )
    config = cloud_speech.RecognitionConfig(
        auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),
        adaptation=adaptation,
        language_codes=["en-US"],
        model="short",
    )

    # Prepare the request which includes specifying the recognizer, configuration, and the audio content
    request = cloud_speech.RecognizeRequest(
        recognizer=f"projects/{PROJECT_ID}/locations/global/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

  1. הדוגמה הזו יוצרת משאב CustomClass עם אותו פריט. לאחר מכן, המערכת יוצרת משאב PhraseSet עם צירוף מילים שמפנה לשם המשאב CustomClass. לאחר מכן הוא מפנה למשאב PhraseSet בבקשת זיהוי:

Python

import os

from google.cloud.speech_v2 import SpeechClient
from google.cloud.speech_v2.types import cloud_speech

PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")


def adaptation_v2_custom_class_reference(
    audio_file: str, phrase_set_id: str, custom_class_id: str
) -> cloud_speech.RecognizeResponse:
    """Transcribe audio file using a custom class.
    Args:
        audio_file (str): Path to the local audio file to be transcribed.
        phrase_set_id (str): The unique ID of the phrase set to use.
        custom_class_id (str): The unique ID of the custom class to use.
    Returns:
        cloud_speech.RecognizeResponse: The full response object which includes the transcription results.
    """
    # Instantiates a speech client
    client = SpeechClient()

    # Reads a file as bytes
    with open(audio_file, "rb") as f:
        audio_content = f.read()

    # Create a custom class to improve recognition accuracy for specific terms
    custom_class = cloud_speech.CustomClass(items=[{"value": "fare"}])
    operation = client.create_custom_class(
        parent=f"projects/{PROJECT_ID}/locations/global",
        custom_class_id=custom_class_id,
        custom_class=custom_class,
    )
    custom_class = operation.result()

    # Create a persistent PhraseSet to reference in a recognition request
    created_phrase_set = cloud_speech.PhraseSet(
        phrases=[
            {
                "value": f"${{{custom_class.name}}}",
                "boost": 20,
            },  # Using custom class reference
        ]
    )
    operation = client.create_phrase_set(
        parent=f"projects/{PROJECT_ID}/locations/global",
        phrase_set_id=phrase_set_id,
        phrase_set=created_phrase_set,
    )
    phrase_set = operation.result()

    # Add a reference of the PhraseSet into the recognition request
    adaptation = cloud_speech.SpeechAdaptation(
        phrase_sets=[
            cloud_speech.SpeechAdaptation.AdaptationPhraseSet(
                phrase_set=phrase_set.name
            )
        ]
    )
    # Automatically detect the audio's encoding with short audio model
    config = cloud_speech.RecognitionConfig(
        auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),
        adaptation=adaptation,
        language_codes=["en-US"],
        model="short",
    )

    # Create a custom class to reference in a PhraseSet
    request = cloud_speech.RecognizeRequest(
        recognizer=f"projects/{PROJECT_ID}/locations/global/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 על המשאבים שבהם השתמשתם בדף הזה, פועלים לפי השלבים הבאים.

  1. אם תרצו, תוכלו לבטל את פרטי הכניסה שיצרתם ולמחוק את הקובץ המקומי של פרטי הכניסה.

    gcloud auth application-default revoke
  2. אם רוצים, מבטלים את פרטי הכניסה של ה-CLI של gcloud.

    gcloud auth revoke

המסוף

  • במסוף Google Cloud , נכנסים לדף Manage resources.

    כניסה לדף Manage resources

  • ברשימת הפרויקטים, בוחרים את הפרויקט שרוצים למחוק ולוחצים על Delete.
  • כדי למחוק את הפרויקט, כותבים את מזהה הפרויקט בתיבת הדו-שיח ולוחצים על Shut down.
  • gcloud

    כדי למחוק Google Cloud פרויקט:

    gcloud projects delete PROJECT_ID

    המאמרים הבאים