資源簡介
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\.myme
?????文件???????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.xm
?????文件????????219??2017-11-09?09:39??語音識別HTML5版本\voiceTest\.settings\org.eclipse.wst.common.project.facet.core.xm
?????文件?????????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.xm
?????文件???????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\me
?????文件????????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\me
?????文件???????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個文件信息
評論
共有 條評論