Java 使用google API将语音转换为带有时间戳的文本
我正在开发一个Java应用程序来将语音转换为文本。我使用Java语音API实现了语音到文本的转换,该API记录音频文件,然后将其转换为FLAC文件,并将其发布到Google,然后将响应转换为字符串。摆在我面前的挑战是,我需要给音频文件中的每个语句加上时间戳(假设检测到fullstop) 如何做到这一点?我是Java新手。Java 使用google API将语音转换为带有时间戳的文本,java,Java,我正在开发一个Java应用程序来将语音转换为文本。我使用Java语音API实现了语音到文本的转换,该API记录音频文件,然后将其转换为FLAC文件,并将其发布到Google,然后将响应转换为字符串。摆在我面前的挑战是,我需要给音频文件中的每个语句加上时间戳(假设检测到fullstop) 如何做到这一点?我是Java新手。 我的主文件: import com.darkprograms.speech.microphone.Microphone; import co
我的主文件:
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来自于此
谢谢你的帮助