我正在开发一个将语音转换为文本的Java应用程序。我使用Java语音API对文本进行了演讲,该语音API记录音频文件,然后将其转换为FLAC文件,将其发布到Google,将响应转换为字符串。我面临的挑战是,我需要在音频文件中为每个单独的声明(假设检测到fullstop)加盖时间戳。
如何做到这一点?我是Java的新手 我的主要档案:
import com.darkprograms.speech.microphone.Microphone;
import com.darkprograms.speech.recognizer.Recognizer;
import javax.sound.sampled.AudioFileFormat;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class DoItAll extends JFrame {
JButton stop = new JButton("Stop");
JButton run = new JButton("Run");
JButton process = new JButton("Process");
Microphone microphone = new Microphone(AudioFileFormat.Type.WAVE);
Recognizer recognizer = new Recognizer();
String audioFile = "c:/eclipse/f.wav";
public DoItAll(){
stop.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
microphone.close();
}
});
run.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
microphone.captureAudioToFile(audioFile);
} catch (Exception e1) {
e1.printStackTrace(); //To change body of catch statement use File
JOptionPane.showMessageDialog(null, e1.getMessage());
}
}
});
process.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String response = "error";
try {
response = recognizer.getRecognizedDataForWave(audioFile).getResponse();
} catch (Exception e1) {
e1.printStackTrace();
response = e1.getMessage();
}
JOptionPane.showMessageDialog(null, response);
}
});
getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS));
getContentPane().add(run);
getContentPane().add(stop);
getContentPane().add(process);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
show();
}
public static void main(String[] args) {
new DoItAll();
}
}
我的演讲API来自此link。
感谢您的帮助。