Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Sie können angeben, dass in Speech-to-Text ein Genauigkeitswert bzw. ein Konfidenzgrad für einzelne Wörter in einer Transkription angegeben wird.
Konfidenz auf Wortebene
Wenn von Speech-to-Text ein Audioclip transkribiert wird, wird auch der Genauigkeitsgrad der Antwort gemessen. Die von Speech-to-Text gesendete Antwort gibt einen Konfidenzgrad für die gesamte Transkriptionsanforderung in Form einer Zahl zwischen 0,0 und 1,0 an.
Das folgende Codebeispiel enthält ein Beispiel für den Konfidenzgradwert, der von Speech-to-Text zurückgegeben wird.
{
"results": [
{
"alternatives": [
{
"transcript": "how old is the Brooklyn Bridge",
"confidence": 0.96748614
}
]
}
]
}
Abgesehen vom Konfidenzgrad der gesamten Transkription kann in Speech-to-Text auch der Konfidenzgrad einzelner Wörter innerhalb der Transkription zur Verfügung gestellt werden. Die Antwort enthält in der Transkription dann WordInfo-Details, mit denen der Konfidenzgrad einzelner Wörter angegeben wird. Dies ist im folgenden Beispiel zu sehen.
{
"results": [
{
"alternatives": [
{
"transcript": "how old is the Brooklyn Bridge",
"confidence": 0.98360395,
"words": [
{
"startOffset": "0s",
"endOffset": "0.300s",
"word": "how",
"confidence": SOME NUMBER
},
...
]
}
]
}
]
}
Konfidenz auf Wortebene in einer Anfrage aktivieren
Im folgenden Code-Snippet wird gezeigt, wie die Konfidenz auf Wortebene in einer Transkriptionsanfrage an Speech-to-Text mithilfe von lokalen und Remote-Dateien aktiviert wird.
Lokale Datei verwenden
Protokoll
Ausführliche Informationen finden Sie unter dem API-Endpunkt speech:recognize.
Für eine synchrone Spracherkennung senden Sie eine POST-Anfrage und geben den entsprechenden Anfragetext an. Das folgende Beispiel zeigt eine POST-Anfrage mit curl. In diesem Beispiel wird die Google Cloud CLI verwendet, um ein Zugriffstoken zu generieren. Eine Anleitung zur Installation der gcloud CLI finden Sie in der Kurzanleitung.
Im folgenden Beispiel wird gezeigt, wie eine POST-Anfrage mit curl gesendet und im Text der Anfrage die Konfidenz auf Wortebene aktiviert wird.
Wenn die Anfrage erfolgreich ist, gibt der Server den HTTP-Statuscode 200 OK und die Antwort im JSON-Format zurück. Diese Informationen sind in einer Datei namens word-level-confidence.txt gespeichert.
fromgoogle.cloudimportspeech_v1p1beta1asspeechclient=speech.SpeechClient()speech_file="resources/Google_Gnome.wav"withopen(speech_file,"rb")asaudio_file:content=audio_file.read()audio=speech.RecognitionAudio(content=content)config=speech.RecognitionConfig(encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,sample_rate_hertz=16000,language_code="en-US",enable_word_confidence=True,)response=client.recognize(config=config,audio=audio)fori,resultinenumerate(response.results):alternative=result.alternatives[0]print("-"*20)print(f"First alternative of result {i}")print(f"Transcript: {alternative.transcript}")print("First Word and Confidence: ({}, {})".format(alternative.words[0].word,alternative.words[0].confidence))returnresponse.results
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-02 (UTC)."],[],[],null,["# Enable word-level confidence\n\n| **Preview**\n|\n|\n| This feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nYou can specify that Speech-to-Text indicate a value of accuracy,\nor [confidence level](/speech-to-text/v2/docs/basics#confidence-values), for\nindividual words in a transcription.\n\nWord-level confidence\n---------------------\n\nWhen the Speech-to-Text transcribes an audio clip, it also\nmeasures the degree of accuracy for the response. The response\nsent from Speech-to-Text states the confidence level for\nthe entire transcription request as a number between 0.0 and 1.0.\nThe following code sample shows an example of the confidence level\nvalue returned by Speech-to-Text. \n\n```\n{\n \"results\": [\n {\n \"alternatives\": [\n {\n \"transcript\": \"how old is the Brooklyn Bridge\",\n \"confidence\": 0.96748614\n }\n ]\n }\n ]\n}\n```\n\nIn addition to the confidence level of the entire transcription,\nSpeech-to-Text can also provide the confidence level of\nindividual words within the transcription. The response then\nincludes [`WordInfo`](/speech-to-text/v2/docs/reference/rest/v2/projects.locations.recognizers/recognize#wordinfo) details in the transcription,\nindicating the confidence level for individual words as shown in the\nfollowing example. \n\n```\n{\n \"results\": [\n {\n \"alternatives\": [\n {\n \"transcript\": \"how old is the Brooklyn Bridge\",\n \"confidence\": 0.98360395,\n \"words\": [\n {\n \"startOffset\": \"0s\",\n \"endOffset\": \"0.300s\",\n \"word\": \"how\",\n \"confidence\": SOME NUMBER\n },\n ...\n ]\n }\n ]\n }\n ]\n}\n```\n\nEnable word-level confidence in a request\n-----------------------------------------\n\nThe following code snippet demonstrates how to enable word-level\nconfidence in a transcription request to Speech-to-Text using local and remote files.\n\n### Use a local file\n\n### Protocol\n\nRefer to the [`speech:recognize`](/speech-to-text/v2/docs/reference/rest/v2/projects.locations.recognizers/recognize)\nAPI endpoint for complete details.\n\n\nTo perform synchronous speech recognition, make a `POST` request and provide the\nappropriate request body. The following shows an example of a `POST` request using\n`curl`. The example uses the [Google Cloud CLI](/sdk) to generate an access\ntoken. For instructions on installing the gcloud CLI,\nsee the [quickstart](/speech-to-text/docs/transcribe-api).\n\nThe following example show how to send a `POST` request using `curl`,\nwhere the body of the request enables word-level confidence. \n\n```bash\ncurl -s -H \"Content-Type: application/json\" \\\n -H \"Authorization: Bearer $(gcloud auth application-default print-access-token)\" \\\n https://speech.googleapis.com/v2/projects/{project}/locations/global/recognizers/{recognizers}:recognize \\\n --data '{\n \"config\": {\n \"features\": {\n \"enableWordTimeOffsets\": true,\n \"enableWordConfidence\": true\n }\n },\n \"uri\": \"gs://cloud-samples-tests/speech/brooklyn.flac\"\n}' \u003e word-level-confidence.txt\n```\n\nIf the request is successful, the server returns a `200 OK` HTTP\nstatus code and the response in JSON format, saved to a file\nnamed `word-level-confidence.txt`. \n\n```\n{\n \"results\": [\n {\n \"alternatives\": [\n {\n \"transcript\": \"how old is the Brooklyn Bridge\",\n \"confidence\": 0.98360395,\n \"words\": [\n {\n \"startTime\": \"0s\",\n \"endTime\": \"0.300s\",\n \"word\": \"how\",\n \"confidence\": 0.98762906\n },\n {\n \"startTime\": \"0.300s\",\n \"endTime\": \"0.600s\",\n \"word\": \"old\",\n \"confidence\": 0.96929157\n },\n {\n \"startTime\": \"0.600s\",\n \"endTime\": \"0.800s\",\n \"word\": \"is\",\n \"confidence\": 0.98271006\n },\n {\n \"startTime\": \"0.800s\",\n \"endTime\": \"0.900s\",\n \"word\": \"the\",\n \"confidence\": 0.98271006\n },\n {\n \"startTime\": \"0.900s\",\n \"endTime\": \"1.100s\",\n \"word\": \"Brooklyn\",\n \"confidence\": 0.98762906\n },\n {\n \"startTime\": \"1.100s\",\n \"endTime\": \"1.500s\",\n \"word\": \"Bridge\",\n \"confidence\": 0.98762906\n }\n ]\n }\n ],\n \"languageCode\": \"en-us\"\n }\n ]\n}\n```\n\n### Python\n\n\nTo learn how to install and use the client library for Speech-to-Text, see\n[Speech-to-Text client libraries](/speech-to-text/docs/client-libraries).\n\n\nFor more information, see the\n[Speech-to-Text Python API\nreference documentation](/python/docs/reference/speech/latest).\n\n\nTo authenticate to Speech-to-Text, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n from google.cloud import speech_v1p1beta1 as speech\n\n client = speech.SpeechClient()\n\n speech_file = \"resources/Google_Gnome.wav\"\n\n with open(speech_file, \"rb\") as audio_file:\n content = audio_file.read()\n\n audio = speech.RecognitionAudio(content=content)\n\n config = speech.RecognitionConfig(\n encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,\n sample_rate_hertz=16000,\n language_code=\"en-US\",\n enable_word_confidence=True,\n )\n\n response = client.recognize(config=config, audio=audio)\n\n for i, result in enumerate(response.results):\n alternative = result.alternatives[0]\n print(\"-\" * 20)\n print(f\"First alternative of result {i}\")\n print(f\"Transcript: {alternative.transcript}\")\n print(\n \"First Word and Confidence: ({}, {})\".format(\n alternative.words[0].word, alternative.words[0].confidence\n )\n )\n\n return response.results\n\n\u003cbr /\u003e"]]