【问题标题】:can i use google speech recognition api in my desktop application我可以在我的桌面应用程序中使用谷歌语音识别 api
【发布时间】:2013-09-15 17:20:43
【问题描述】:

我想知道我是否可以将谷歌的语音识别 api 用于我的桌面应用程序。我已经看到了一些示例,其中我必须将语音转换为文件并发送到 url。但这将是一项繁琐的任务,因为在我的应用程序中,用户必须不断提交他的声音。那么有没有其他替代方法可以使用谷歌语音 api。我对使用 sphinx 最不感兴趣,因为它的准确性非常低,而且我不知道如何在字典中添加新单词,如果不将其添加到字典中,它就不会识别新单词。任何帮助将不胜感激。

【问题讨论】:

  • 知道是API却不知道能不能用?我想说你可以使用任何 API。

标签: java speech-recognition speech-to-text cmusphinx


【解决方案1】:

您指的是环境聆听吗?我实际上正在使用 Google Speech Recognition API 研究一些语音活动检测算法。虽然我还没有完成算法,但我已经添加了一个音量和频率计算器,这样您就不必在对方不说话时向 Google 发送请求。这是源代码的链接。

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();
    }
}

【讨论】:

  • 你有一些示例代码如何执行它。这对我来说很棒,因为我必须在本月底之前向客户展示它
  • 您可以下载一个示例分支,但我将编辑我的答案以包含示例代码。
  • 它给了很多问题,你能给我你的邮件ID,这样我就可以和你讨论我的问题并将我的代码发送给你,或者你只是给我发一封测试邮件到 tarunvermacdac@gmail.com
  • 我给你发了一封邮件,但我还没有收到回复。
  • 谢谢你解决了我的问题。非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-30
相关资源
最近更新 更多