Reconhecimento de pontuação síncrono

Realiza a transcrição com pontuação automática nos dados brutos de áudio em PCM.

Exemplo de código

Java

/**
 * Performs transcription with automatic punctuation on raw PCM audio data.
 *
 * @param fileName the path to a PCM audio file to transcribe.
 */
public static void transcribeFileWithAutomaticPunctuation(String fileName) throws Exception {
  Path path = Paths.get(fileName);
  byte[] content = Files.readAllBytes(path);

  try (SpeechClient speechClient = SpeechClient.create()) {
    // Configure request with local raw PCM audio
    RecognitionConfig recConfig =
        RecognitionConfig.newBuilder()
            .setEncoding(AudioEncoding.LINEAR16)
            .setLanguageCode("en-US")
            .setSampleRateHertz(16000)
            .setEnableAutomaticPunctuation(true)
            .build();

    // Get the contents of the local audio file
    RecognitionAudio recognitionAudio =
        RecognitionAudio.newBuilder().setContent(ByteString.copyFrom(content)).build();

    // Perform the transcription request
    RecognizeResponse recognizeResponse = speechClient.recognize(recConfig, recognitionAudio);

    // Just print the first result here.
    SpeechRecognitionResult result = recognizeResponse.getResultsList().get(0);

    // There can be several alternative transcripts for a given chunk of speech. Just use the
    // first (most likely) one here.
    SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0);

    // Print out the result
    System.out.printf("Transcript : %s\n", alternative.getTranscript());
  }
}

A seguir

Para pesquisar e filtrar exemplos de código de outros produtos do Google Cloud, consulte o navegador de exemplos do Google Cloud.