javaweb实现语音识别


javaweb实现语音识别,将语音转换成文字并输出,调用百度接口,需要自己注册账号。
资源截图
代码片段和文件信息
package com.xin.voice.controller;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.xin.voice.util.SampleClient;
/**
 * H5 录音实现
 * @author liyingming
 *
 */

@Controller
@RequestMapping(value = “/voiceSpeech“)
public class VoiceSpeechController {

SampleClient sc = new SampleClient(); //语音识别核心类

/**
 * 访问录音页面
 * @return
 * @throws Exception
 */
@RequestMapping(value = “/voice.do“)
public ModelAndView queryVoice() throws Exception {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName(“/voice/voiceIndex“);
return modelAndView;
}

/**
 * 保存录音
 * @date 2017年9月25日 上午10:33:48
 * @param audioData
 * @return
 * @throws Exception
 */

@RequestMapping(value = “/save.do“)
@ResponseBody
public Mapject> save(MultipartFile audioDataHttpServletRequest request){
Mapject> modelMap = new HashMapject>();
try {
//保存录音
String filePathName =saveAudio(audioData);//返回音频路径名称
//识别录音
String Rtext = “未识别清楚“;
if ((filePathName)!=““) {
Rtext = sc.getSynthesis(filePathName);
modelMap.put(“success“ true);
}


System.out.println(“语音识别的内容:“ + Rtext);
modelMap.put(“Rtext“ Rtext);

        } catch (Exception e) {
            e.printStackTrace();
            modelMap.put(“success“ false);
modelMap.put(“data“ e.getMessage());
        }
return modelMap;
}

/**
 * 保存音频文件
 * @param audioData
 * @return
 */
private String saveAudio(MultipartFile audioData){
try {
String filePathName = null;
String fName = System.currentTimeMillis() + “.wav“;
        String fPath = “C:/testvoice“;
        //将录音的文件存放到F盘下语音文件夹下  
        File filePath = new File(fPath);  
        if(!filePath.exists())  
        {//如果文件不存在,则创建该目录  
            filePath.mkdir();  
        }  
        filePathName = fPath+“/“+fName;
FileOutputStream os = new FileOutputStream(filePathName); 
System.out.println(“路径:“+filePathName);
        InputStream in = audioData.getInputStream(); 
        
        int b = 0;  
        while((b=in.read())!=-1){ //读取文件   
            os.write(b);  
        }  
        os.flush(); //关闭流   
        in.close();  
        os.close();  
        return filePathName;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       4005  2017-12-11 23:26  语音识别HTML5版本voiceTest.classpath

     文件        303  2014-12-26 10:53  语音识别HTML5版本voiceTest.mymetadata

     文件       1752  2017-11-09 09:39  语音识别HTML5版本voiceTest.project

     文件        500  2014-11-03 14:02  语音识别HTML5版本voiceTest.settings.jsdtscope

     文件        248  2017-12-11 12:52  语音识别HTML5版本voiceTest.settingscom.genuitec.eclipse.migration.prefs

     文件         57  2018-03-14 15:23  语音识别HTML5版本voiceTest.settingsorg.eclipse.core.resources.prefs

     文件        670  2017-11-09 09:39  语音识别HTML5版本voiceTest.settingsorg.eclipse.jdt.core.prefs

     文件        106  2017-11-09 09:39  语音识别HTML5版本voiceTest.settingsorg.eclipse.ltk.core.refactoring.prefs

     文件        570  2017-11-09 09:39  语音识别HTML5版本voiceTest.settingsorg.eclipse.wst.common.component

     文件        172  2017-12-11 12:52  语音识别HTML5版本voiceTest.settingsorg.eclipse.wst.common.project.facet.core.prefs.xml

     文件        219  2017-11-09 09:39  语音识别HTML5版本voiceTest.settingsorg.eclipse.wst.common.project.facet.core.xml

     文件         49  2014-11-03 14:02  语音识别HTML5版本voiceTest.settingsorg.eclipse.wst.jsdt.ui.superType.container

     文件          6  2014-11-03 14:02  语音识别HTML5版本voiceTest.settingsorg.eclipse.wst.jsdt.ui.superType.name

     文件        842  2014-12-29 11:06  语音识别HTML5版本voiceTestapp-configconfigapplicationContext.xml

     文件       3099  2018-03-14 14:56  语音识别HTML5版本voiceTestsrccomxinvoicecontrollerVoiceSpeechController.java

     文件       3108  2018-03-22 14:31  语音识别HTML5版本voiceTestsrccomxinvoiceutilAuthService.java

     文件       1966  2018-03-22 14:31  语音识别HTML5版本voiceTestsrccomxinvoiceutilSampleClient.java

     文件       2030  2017-12-12 11:33  语音识别HTML5版本voiceTestsrccomxinvoiceutilSampleClient.java.bak

     文件         40  2017-12-11 12:52  语音识别HTML5版本voiceTestsrcmeta-INFMANIFEST.MF

     文件        834  2014-11-03 14:02  语音识别HTML5版本voiceTestWebContentindex.jsp

     文件       7793  2018-03-14 15:40  语音识别HTML5版本voiceTestWebContentjsHZRecorder.js

     文件      93682  2018-03-14 15:40  语音识别HTML5版本voiceTestWebContentjsjquery-1.8.3.min.js

     文件         39  2017-11-09 09:39  语音识别HTML5版本voiceTestWebContentmeta-INFMANIFEST.MF

     文件       4176  2017-11-13 16:48  语音识别HTML5版本voiceTestWebContentvoice1510562930942.mp3

     文件       4176  2017-11-13 16:48  语音识别HTML5版本voiceTestWebContentvoice1510562931523.mp3

     文件       4176  2017-12-11 15:31  语音识别HTML5版本voiceTestWebContentvoice1512977484954.mp3

     文件       4176  2017-12-11 15:32  语音识别HTML5版本voiceTestWebContentvoice1512977549596.mp3

     文件       4176  2017-12-11 15:33  语音识别HTML5版本voiceTestWebContentvoice1512977593181.mp3

     文件       4176  2017-12-11 15:33  语音识别HTML5版本voiceTestWebContentvoice1512977600189.mp3

     文件       4176  2017-12-11 15:33  语音识别HTML5版本voiceTestWebContentvoice1512977615294.mp3

............此处省略77个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)