Google SpeechAPIに接続して喋った内容を文字で出力するというJavaプログラムを作ったのですが、どうやらここのコードでどうしても処理が遅くなり、完全に処理するまで10秒程度掛かってしまいます。
もっと処理を軽量化することは可能でしょうか?
Java
1 // リニアPCM 16bit 15000Hz × 10秒間 = 300000byte 2 private byte[] voiceData = new byte[300000]; 3 4 private static AudioFormat audioFormat; 5 private static DataLine.Info info; 6 private static TargetDataLine target; 7 8 public static void init() throws LineUnavailableException { 9 audioFormat = new AudioFormat(15000, 16, 1, true, false); 10 info = new DataLine.Info(TargetDataLine.class, audioFormat); 11 12 target = (TargetDataLine) AudioSystem.getLine(info); 13 target.open(audioFormat); // ここで処理が遅くなる // 14 } 15 16 /* 録音開始 */ 17 public void startRec() throws IOException { 18 System.out.println("マイク入力開始..."); 19 target.start(); 20 AudioInputStream inputStream = new AudioInputStream(target); 21 inputStream.read(voiceData, 0, voiceData.length); 22 } 23 24 /* 録音停止 */ 25 public void stopRec() { 26 target.stop(); 27 target.close(); 28 System.out.println("マイク入力停止"); 29 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/07/11 10:42
2018/07/11 18:37