我想知道我是否可以在我的桌面应用程序中使用 google 的语音识别 api。我见过一些示例,其中我必须将语音转换为文件并发送到网址。但这将是一个不太麻烦的任务,因为在我的应用程序中,用户必须不断提交他的声音。那么还有其他替代方法可以使用 google voice api 吗?我对狮身人面像最不感兴趣,因为它的准确性非常低,而且我不知道如何在字典中添加新单词,并且如果不将其添加到字典中,它就无法识别新单词。任何帮助,将不胜感激。
您指的是环境聆听吗?我实际上正在使用 Google 语音识别 API 开发一些语音活动检测算法。虽然我还没有完成算法,但我添加了一个音量和频率计算器,这样你就不必在对方不说话时向 Google 发送请求。这是源代码的链接。
https://github.com/The-Shadow/java-speech-api https://github.com/The-Shadow/java-speech-api
(这不是我使用的,但它很简单。您还可以添加频率阈值保持和其他内容。我将此代码放在一起,因此不能保证它能够工作,请查看 API 的示例分支。)
//package recognitionprocess;
//import org.jaudiotagger.audio.*;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import javax.sound.sampled.AudioFileFormat;
import com.darkprograms.speech.recognizer.GoogleResponse;
import com.darkprograms.speech.recognizer.Recognizer;
public class RecognitionMain {
public static void main(String[] args) {
try{
ambientListening();
}
catch(Exception e){
e.printStackTrace();
}
}
private static void ambientListening() throws Exception{
String filename = "tarunaudio.wav";//Your Desired FileName
MicrophoneAnalyzer mic = new MicrophoneAnalyzer(AudioFileFormat.Type.WAVE);
mic.open();
mic.captureAudioToFile(filename);
final int THRESHOLD = 10;//YOUR THRESHOLD VALUE.
int ambientVolume = mic.getAudioVolume();//
int speakingVolume = -2;
boolean speaking = false;
for(int i = 0; i<1||speaking; i++){
int volume = mic.getAudioVolume();
System.out.println(volume);
if(volume>ambientVolume+THRESHOLD){
speakingVolume = volume;
speaking = true;
Thread.sleep(1000);
System.out.println("SPEAKING");
}
if(speaking && volume+THRESHOLD<speakingVolume){
break;
}
Thread.sleep(200);//Your refreshRate
}
mic.close();
//You can also measure the volume across the entire file if you want
//to be resource intensive.
if(!speaking){
ambientListening();
}
Recognizer rec = new Recognizer(Recognizer.Languages.ENGLISH_US);
GoogleResponse out = rec.getRecognizedDataForWave(filename);
System.out.println(out.getResponse());
ambientListening();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)