Automatische Zeichensetzung abrufen

Auf dieser Seite wird beschrieben, wie Sie in Transkriptionsergebnisse von Speech-to-Text automatisch Satzzeichen erhalten. Wenn Sie diese Funktion aktivieren, leitet Speech-to-Text automatisch die Präsenz, Kommas und Fragezeichen in den Audiodaten ab und fügt sie dem Transkript hinzu.

Standardmäßig fügt Speech-to-Text in die Ergebnisse der Spracherkennung keine Satzzeichen ein. Sie können Speech-to-Text aber anweisen, Satzzeichen automatisch zu erkennen und in Transkriptionsergebnisse einzufügen. Wenn Sie die automatische Zeichensetzung aktivieren, wird Speech-to-Text automatisch auch nach jedem Punkt und Fragezeichen automatisch großgeschrieben.

Hinweise

  1. 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.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Die Abrechnung für das Google Cloud-Projekt muss aktiviert sein.

  4. Enable the Speech-to-Text APIs.

    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 colunn 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.

      Zu IAM
    2. Wählen Sie das Projekt aus.
    3. Klicken Sie auf Zugriff erlauben.
    4. Geben Sie im Feld Neue Hauptkonten Ihre Nutzer-ID ein. Dies ist in der Regel die E-Mail-Adresse eines Google-Kontos.

    5. Wählen Sie in der Liste Rolle auswählen eine Rolle aus.
    6. Wenn Sie weitere Rollen hinzufügen möchten, klicken Sie auf Weitere Rolle hinzufügen und fügen Sie weitere Rollen hinzu.
    7. Klicken Sie auf Speichern.
    8. Install the Google Cloud CLI.
    9. To initialize the gcloud CLI, run the following command:

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

      Go to project selector

    11. Die Abrechnung für das Google Cloud-Projekt muss aktiviert sein.

    12. Enable the Speech-to-Text APIs.

      Enable the APIs

    13. 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 colunn 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.

        Zu IAM
      2. Wählen Sie das Projekt aus.
      3. Klicken Sie auf Zugriff erlauben.
      4. Geben Sie im Feld Neue Hauptkonten Ihre Nutzer-ID ein. Dies ist in der Regel die E-Mail-Adresse eines Google-Kontos.

      5. Wählen Sie in der Liste Rolle auswählen eine Rolle aus.
      6. Wenn Sie weitere Rollen hinzufügen möchten, klicken Sie auf Weitere Rolle hinzufügen und fügen Sie weitere Rollen hinzu.
      7. Klicken Sie auf Speichern.
      8. Install the Google Cloud CLI.
      9. To initialize the gcloud CLI, run the following command:

        gcloud init
      10. Clientbibliotheken können Standardanmeldedaten für Anwendungen verwenden, um sich einfach bei Google APIs zu authentifizieren und Anfragen an diese APIs zu senden. Mit den Standardanmeldedaten für Anwendungen können Sie Ihre Anwendung lokal testen und bereitstellen, ohne den zugrunde liegenden Code zu ändern. Weitere Informationen finden Sie unter Authentifizieren Sie sich für die Verwendung von Clientbibliotheken.

      11. If you're using a local shell, then create local authentication credentials for your user account:

        gcloud auth application-default login

        You don't need to do this if you're using Cloud Shell.

      Prüfen Sie außerdem, ob Sie die Clientbibliothek installiert haben.

      Transkriptionsanfrage mit automatischer Zeichensetzung stellen

      Die folgenden Codebeispiele zeigen, wie Sie bei einer Transkriptionsanfrage Satzzeichen einfügen lassen.

      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 transcribe_auto_punctuation_v2(audio_file: str) -> cloud_speech.RecognizeResponse:
          """Transcribe an audio file with automatically detect and insert punctuation in transcription results.
          Args:
              audio_file (str): Path to the local audio file to be transcribed.
          """
          # Instantiates a client
          client = SpeechClient()
      
          # Reads a file as bytes
          with open(audio_file, "rb") as f:
              audio_content = f.read()
      
          config = cloud_speech.RecognitionConfig(
              auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),
              language_codes=["en-US"],
              model="long",
              features=cloud_speech.RecognitionFeatures(
                  # Enable automatic punctuation
                  enable_automatic_punctuation=True,
              ),
          )
      
          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
      
      

      Weitere Informationen zum Konfigurieren verschiedener Features finden Sie in der Referenzdokumentation zu RecognitionFeatures.

      Bereinigen

      Mit den folgenden Schritten vermeiden Sie, dass Ihrem Google Cloud-Konto die in dieser Anleitung verwendeten Ressourcen in Rechnung gestellt werden:

      1. Optional: Revoke the authentication credentials that you created, and delete the local credential file.

        gcloud auth application-default revoke
      2. Optional: Revoke credentials from the gcloud CLI.

        gcloud auth revoke

      Console

    14. In the Google Cloud console, go to the Manage resources page.

      Go to Manage resources

    15. In the project list, select the project that you want to delete, and then click Delete.
    16. In the dialog, type the project ID, and then click Shut down to delete the project.
    17. gcloud

      Delete a Google Cloud project:

      gcloud projects delete PROJECT_ID

      Nächste Schritte