Reconhece a pontuação de forma síncrona

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

Exemplo de código

Java

Para saber como instalar e usar a biblioteca cliente do Speech-to-Text, consulte o artigo Bibliotecas cliente do Speech-to-Text. Para mais informações, consulte a documentação de referência da API Java Speech-to-Text.

Para se autenticar no Speech-to-Text, configure as Credenciais padrão da aplicação. Para mais informações, consulte o artigo Configure a autenticação para um ambiente de desenvolvimento local.

/**
 * 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());
  }
}

O que se segue?

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