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 unter Spracherkennung – Grundlagen.
Hinweise
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Speech-to-Text APIs.
-
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.
Zu IAM - Wählen Sie das Projekt aus.
- Klicken Sie auf Zugriff erlauben.
-
Geben Sie im Feld Neue Hauptkonten Ihre Nutzer-ID ein. Dies ist in der Regel die E-Mail-Adresse eines Google-Kontos.
- Wählen Sie in der Liste Rolle auswählen eine Rolle aus.
- Wenn Sie weitere Rollen hinzufügen möchten, klicken Sie auf Weitere Rolle hinzufügen und fügen Sie weitere Rollen hinzu.
- Klicken Sie auf Speichern.
Install the Google Cloud CLI.
Wenn Sie einen externen Identitätsanbieter (IdP) verwenden, müssen Sie sich zuerst mit Ihrer föderierten Identität in der gcloud CLI anmelden.
Führen Sie folgenden Befehl aus, um die gcloud CLI zu initialisieren:
gcloud init
-
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Speech-to-Text APIs.
-
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.
Zu IAM - Wählen Sie das Projekt aus.
- Klicken Sie auf Zugriff erlauben.
-
Geben Sie im Feld Neue Hauptkonten Ihre Nutzer-ID ein. Dies ist in der Regel die E-Mail-Adresse eines Google-Kontos.
- Wählen Sie in der Liste Rolle auswählen eine Rolle aus.
- Wenn Sie weitere Rollen hinzufügen möchten, klicken Sie auf Weitere Rolle hinzufügen und fügen Sie weitere Rollen hinzu.
- Klicken Sie auf Speichern.
Install the Google Cloud CLI.
Wenn Sie einen externen Identitätsanbieter (IdP) verwenden, müssen Sie sich zuerst mit Ihrer föderierten Identität in der gcloud CLI anmelden.
Führen Sie folgenden Befehl aus, um die gcloud CLI zu initialisieren:
gcloud init
-
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.wav
durch 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.txt
Verwenden 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/_:recognize
Die Antwort sieht ungefähr so aus:
{ "results": [ { "alternatives": [ { "transcript": "how old is the Brooklyn Bridge", "confidence": 0.98267895 } ] } ] }
-
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
- 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.
- 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.
- Verwenden Sie Clientbibliotheken, um Audio mit Ihrer bevorzugten Programmiersprache zu transkribieren.
- Transkribieren kurzer Audiodateien üben
- Weitere Informationen zum Transkribieren von Audiostreams
- Lange Audiodateien transkribieren
- Best Practices-Dokumentation für maximale Leistung und Genauigkeit sowie für weitere Tipps
Anfrage zur Audiotranskription stellen
Mit dem folgenden Codebeispiel können Sie eine recognize
-REST-Anfrage an die Speech-to-Text API senden.
Sie haben Ihre erste Anfrage an Speech-to-Text gesendet.
Bereinigen
Mit den folgenden Schritten vermeiden Sie, dass Ihrem Google Cloud -Konto die auf dieser Seite verwendeten Ressourcen in Rechnung gestellt werden:
Console
gcloud