Audio mit mehreren Kanälen transkribieren

Auf dieser Seite wird beschrieben, wie Sie mit Speech-to-Text Audiodateien transkribieren, die mehr als einen Kanal enthalten. Die Multikanal-Erkennung ist für alle Audiocodierungen, die von Speech-to-Text unterstützt werden, für bis zu acht Kanäle verfügbar.

Wenn Sie AutoDetectDecodingConfig verwenden, müssen Sie nicht angeben, wie viele Audiokanäle die Datei hat. Dies wird automatisch ermittelt. Sie müssen die Anzahl der Audiokanäle angeben, wenn Sie ExplicitDecodingConfig verwenden.

Audiodaten enthalten in der Regel einen Kanal für jeden Sprecher in der Aufzeichnung. Audiodaten von zwei Personen, die sich über das Telefon unterhalten, können beispielsweise zwei Kanäle enthalten, da jede Leitung separat aufgezeichnet wird.

Wenn Sie eine Anfrage mit mehreren Kanälen senden, gibt Speech-to-Text ein Ergebnis zurück, das die verschiedenen in den Audiodaten enthaltenen Kanäle identifiziert und die Alternativen für jedes Ergebnis mit dem Feld channel_tag kennzeichnet.

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.

      Synchrone Spracherkennung für eine Multikanal-Datei durchführen

      Im Folgenden finden Sie ein Beispiel für eine synchrone Spracherkennung für eine lokale Multikanal-Audiodatei:

      Python

      import os
      
      from google.cloud.speech_v2 import SpeechClient
      from google.cloud.speech_v2.types import cloud_speech
      
      PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
      
      
      def transcribe_multichannel_v2(
          audio_file: str,
      ) -> cloud_speech.RecognizeResponse:
          """Transcribe the given audio file synchronously with multichannel.
          Args:
              audio_file (str): Path to the local audio file to be transcribed.
                  Example: "resources/two_channel_16k.wav"
          Returns:
              cloud_speech.RecognizeResponse: The full response object which includes the transcription results.
          """
          # 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(
                  multi_channel_mode=cloud_speech.RecognitionFeatures.MultiChannelMode.SEPARATE_RECOGNITION_PER_CHANNEL,
              ),
          )
      
          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}")
              print(f"Channel tag: {result.channel_tag}")
      
          return response
      

      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