בדף הזה מוסבר איך מגדירים כלי לזיהוי שפה כדי לזהות אוטומטית את השפה שמדוברת בקובץ אודיו, מתוך רשימה מוגדרת מראש של שפות פוטנציאליות.
במצבים מסוימים, אתם לא יודעים בוודאות באיזו שפה הקלטות האודיו שלכם. לדוגמה, אם אתם מפרסמים את השירות, האפליקציה או המוצר שלכם במדינה עם כמה שפות רשמיות, יכול להיות שתקבלו קלט אודיו ממשתמשים במגוון שפות. לכן, יכול להיות שיהיה קשה יותר לציין קוד שפה יחיד לבקשות תמלול.
זיהוי של כמה שפות
ב-Cloud Speech-to-Text יש אפשרות לציין קבוצה של שפות שעשויות להופיע בנתוני האודיו. כשיוצרים Recognizer או שולחים בקשת זיהוי, אפשר לציין בשדה language_codes שפה אחת או יותר שנתוני האודיו עשויים לכלול. בבקשה עם כמה שפות, Cloud Speech-to-Text מנסה לתמלל את האודיו באמצעות השפה המתאימה ביותר מתוך רשימת החלופות שסיפקתם.
לאחר מכן, Cloud Speech-to-Text מתייג את תוצאות התמלול באמצעות קוד השפה החזוי.
התכונה הזו מתאימה במיוחד לאפליקציות שצריכות לתמלל הצהרות קצרות כמו פקודות קוליות או חיפושים. אפשר לציין עד שלוש שפות לזיהוי שפה אוטומטי.
לפני שמתחילים
-
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
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.enablepermission. 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.-
Make sure that you have the following role or roles on the project: Cloud Speech Administrator
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
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.
- 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
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
- Click Grant access.
-
In the New principals field, enter your user identifier. This is typically the identifier for a user in a workforce identity pool. For details, see Represent workforce pool users in IAM policies, or contact your administrator.
- Click Select a role, then search for the role.
- To grant additional roles, click Add another role and add each additional role.
- Click Save.
-
-
Install the Google Cloud CLI.
-
Configure the gcloud CLI to use your federated identity.
For more information, see Sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud initבספריות הלקוח אפשר להשתמש ב-Application Default Credentials כדי לעבור בקלות אימות מול Google APIs ולשלוח בקשות לאותם ממשקי API. באמצעות Application Default Credentials, אתם יכולים לבדוק את האפליקציה ברמה המקומית ולפרוס אותה בלי לשנות את הקוד שלה. מידע נוסף זמין במאמר אימות לצורך שימוש בספריות לקוח.
-
יוצרים פרטי כניסה לאימות מקומי עבור חשבון המשתמש:
gcloud auth application-default login
אם מוחזרת שגיאת אימות, צריך לוודא ש נכנסתם ל-CLI של gcloud באמצעות הזהות המאוחדת שלכם.
צריך גם לוודא שספריית הלקוח מותקנת.
הפעלת זיהוי שפה בבקשות לתמלול אודיו
הנה דוגמה לביצוע זיהוי דיבור סינכרוני בקובץ אודיו מקומי עם כמה שפות.
Python
הסרת המשאבים
כדי לא לצבור חיובים לחשבון Google Cloud על המשאבים שבהם השתמשתם בדף הזה, פועלים לפי השלבים הבאים.
-
אם תרצו, תוכלו לבטל את פרטי הכניסה לאימות שיצרתם ולמחוק את הקובץ המקומי של פרטי הכניסה.
gcloud auth application-default revoke
-
אם רוצים, מבטלים את פרטי הכניסה של ה-CLI של gcloud.
gcloud auth revoke
המסוף
gcloud
כדי למחוק Google Cloud פרויקט:
gcloud projects delete PROJECT_ID
המאמרים הבאים
- איך מתמללים קובצי אודיו קצרים
- איך מתמללים אודיו בסטרימינג
- איך מתמללים קובצי אודיו ארוכים
- לשיפור הביצועים והדיוק, ולקבלת טיפים נוספים, אפשר לעיין במסמכי התיעוד בנושא שיטות מומלצות.