• 大小: 10.8MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-08-23
  • 语言: Java
  • 标签: 语音识别  

资源简介

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\.settings\com.genuitec.eclipse.migration.prefs

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

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

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

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

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

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

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

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

     文件        842  2014-12-29 11:06  语音识别HTML5版本\voiceTest\app-config\config\applicationContext.xml

     文件       3099  2018-03-14 14:56  语音识别HTML5版本\voiceTest\src\com\xin\voice\controller\VoiceSpeechController.java

     文件       3108  2018-03-22 14:31  语音识别HTML5版本\voiceTest\src\com\xin\voice\util\AuthService.java

     文件       1966  2018-03-22 14:31  语音识别HTML5版本\voiceTest\src\com\xin\voice\util\SampleClient.java

     文件       2030  2017-12-12 11:33  语音识别HTML5版本\voiceTest\src\com\xin\voice\util\SampleClient.java.bak

     文件         40  2017-12-11 12:52  语音识别HTML5版本\voiceTest\src\meta-INF\MANIFEST.MF

     文件        834  2014-11-03 14:02  语音识别HTML5版本\voiceTest\WebContent\index.jsp

     文件       7793  2018-03-14 15:40  语音识别HTML5版本\voiceTest\WebContent\js\HZRecorder.js

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

     文件         39  2017-11-09 09:39  语音识别HTML5版本\voiceTest\WebContent\meta-INF\MANIFEST.MF

     文件       4176  2017-11-13 16:48  语音识别HTML5版本\voiceTest\WebContent\voice\1510562930942.mp3

     文件       4176  2017-11-13 16:48  语音识别HTML5版本\voiceTest\WebContent\voice\1510562931523.mp3

     文件       4176  2017-12-11 15:31  语音识别HTML5版本\voiceTest\WebContent\voice\1512977484954.mp3

     文件       4176  2017-12-11 15:32  语音识别HTML5版本\voiceTest\WebContent\voice\1512977549596.mp3

     文件       4176  2017-12-11 15:33  语音识别HTML5版本\voiceTest\WebContent\voice\1512977593181.mp3

     文件       4176  2017-12-11 15:33  语音识别HTML5版本\voiceTest\WebContent\voice\1512977600189.mp3

     文件       4176  2017-12-11 15:33  语音识别HTML5版本\voiceTest\WebContent\voice\1512977615294.mp3

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

评论

共有 条评论