동기식으로 구두점 인식

원시 PCM 오디오 데이터에서 자동 구두점을 사용하여 텍스트 변환을 수행합니다.

코드 샘플

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

다음 단계

다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저를 참조하세요.