Auf dieser Seite wird gezeigt, wie Sie mithilfe der REST-Schnittstelle und des Befehls curl eine Spracherkennungsanfrage an Speech-to-Text senden.
Speech-to-Text ermöglicht die einfache Einbindung von Google-Spracherkennungstechnologien in Entwickleranwendungen. Sie können Audiodaten an die Speech-to-Text API senden, die dann eine Texttranskription dieser Audiodatei zurückgibt. Weitere Informationen zu diesem Dienst finden Sie auf der Seite mit Grundlagen zu Cloud Speech-to-Text.
Hinweis
-
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.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. 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.
IAM aufrufen - Wählen Sie das Projekt aus.
- Klicken Sie auf Zugriffsrechte erteilen.
-
Geben Sie im Feld Neue Hauptkonten Ihre Nutzer-ID ein. Bei einem Nutzer in einem Mitarbeiteridentitätspool ist dies in der Regel dessen Kennung. Weitere Informationen erhalten Sie unter Mitarbeiteridentitätspool-Nutzer in IAM-Richtlinien darstellen oder von Ihrem Administrator.
- Wählen Sie in der Liste Rolle auswählen eine Rolle aus.
- Klicken Sie auf Weitere Rolle hinzufügen, wenn Sie weitere Rollen zuweisen möchten.
- Klicken Sie auf Speichern.
Install the Google Cloud CLI.
Konfigurieren Sie die gcloud CLI für die Verwendung Ihrer föderierten Identität.
Weitere Informationen finden Sie unter Mit Ihrer föderierten Identität in der gcloud CLI anmelden.
Führen Sie folgenden Befehl aus, um die gcloud CLI zu initialisieren:
gcloud initAnfrage zur Audiotranskription stellen
Mit dem folgenden Codebeispiel können Sie eine
recognize-REST-Anfrage an die Speech-to-Text API senden.Führen Sie diesen Befehl aus, um eine JSON-Datei als Eingabe für die Anfrage zu erstellen. Ersetzen Sie
/full/path/to/audio/file.wavdurch den Pfad zur Audiodatei, die Sie transkribieren möchten:echo "{ \"config\": { \"auto_decoding_config\": {}, \"language_codes\": [\"en-US\"], \"model\": \"long\" }, \"content\": \"$(base64 -w 0 /full/path/to/audio/file.wav | sed 's/+/-/g; s/\//_/g')\" }" > /tmp/data.txtVerwenden Sie
curl, um einerecognize-Anfrage zu stellen:curl -X POST -H "Content-Type: application/json; charset=utf-8" \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -d @/tmp/data.txt \ https://speech.googleapis.com/v2/projects/PROJECT_ID/locations/global/recognizers/_:recognizeDie Antwort sieht ungefähr so aus:
{ "results": [ { "alternatives": [ { "transcript": "how old is the Brooklyn Bridge", "confidence": 0.98267895 } ] } ] }
Sie haben Ihre erste Anfrage an Speech-to-Text gesendet.
Bereinigen
Mit den folgenden Schritten vermeiden Sie, dass Ihrem Konto von Google Cloud die auf dieser Seite verwendeten Ressourcen in Rechnung gestellt werden:
-
Optional: Revoke the authentication credentials that you created, and delete the local credential file.
gcloud auth application-default revoke
-
Optional: Revoke credentials from the gcloud CLI.
gcloud auth revoke
Console
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
gcloud
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
Weitere Informationen
- Clientbibliotheken verwenden, um Audio mit Ihrer bevorzugten Programmiersprache zu transkribieren
- Kurze Audiodateien transkribieren
- Audiostreams transkribieren
- Lange Audiodateien transkribieren
- Best Practices-Dokumentation mit Tipps zu Leistung, Accuracy und anderen Themen
-