Java
SDK
Watson
stt

Watson Java SDK 3.5.0 で Speech To Text 日本語

More than 1 year has passed since last update.

https://github.com/watson-developer-cloud/java-sdk/blob/master/speech-to-text/README.md

java-sdk-3.5.0-jar-with-dependencies.jar

SDK 3.5.0 の、日本語のときのオプション設定が不明だったので。

package stt;

import java.io.File;

import com.ibm.watson.developer_cloud.http.HttpMediaType;
import com.ibm.watson.developer_cloud.speech_to_text.v1.SpeechToText;
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.RecognizeOptions;
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.SpeechAlternative;
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.SpeechResults;
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.Transcript;

public class SpeechToTextExample {

    public static void main(String[] args) throws Exception {

        String endPoint = "https://stream.watsonplatform.net/speech-to-text/api";
        String username = "xxx";
        String password = "yyy";
        String wavFile = "file/input.wav";
        String model = "ja-JP_BroadbandModel";

        SpeechToText service = new SpeechToText();
        service.setUsernameAndPassword(username, password);

        RecognizeOptions recognizeOptions = new RecognizeOptions.Builder()
                .contentType(HttpMediaType.AUDIO_WAV) //
                .continuous(true) //
                .interimResults(true) //
                .model(model) //
                .build();

        File audio = new File(wavFile);
        service.setEndPoint(endPoint);

        long time1 = System.currentTimeMillis();
        SpeechResults transcript = service.recognize(audio, recognizeOptions)
                .execute();
        long time2 = System.currentTimeMillis();
        System.err.println("time:" + (time2 - time1));

        // System.out.println(transcript);
        // System.out.println();
        for (Transcript t : transcript.getResults()) {
            // System.out.println(t.toString());
            for (SpeechAlternative a : t.getAlternatives()) {
                System.out.println(a.getTranscript());
            }
        }
    }
}


以下、結果。

time:5152
今日 は 桜 が きれい だった
久々 に 六本木 に 行った けど いろいろ 新しい ビル が 増えてる ね