首次讲讲思路,如果说不定大佬们也可以自己完成  ,如果大佬们懒得弄那就直接

看这里看这里

上面我已经实现了语音的实时录入检测识别并且附带了录入和识别的子项目

1.)本地语音的实时录入、并检测是否有语音录入判断是否休眠

package com.wqc.sound;import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.TargetDataLine;public class EngineeCore {String filePath = "E:\\1jAVE\\ECLIPSE\\obj\\nls-example-recognizer\\src\\main\\resources\\voice_cache.wav";AudioFormat audioFormat;TargetDataLine targetDataLine;boolean flag = true;private void stopRecognize() {flag = false;targetDataLine.stop();targetDataLine.close();}private AudioFormat getAudioFormat() {float sampleRate = 16000;// 8000,11025,16000,22050,44100int sampleSizeInBits = 16;// 8,16int channels = 1;// 1,2boolean signed = true;// true,falseboolean bigEndian = false;// true,falsereturn new AudioFormat(sampleRate, sampleSizeInBits, channels, signed, bigEndian);}// end getAudioFormatvoid startRecognize() {try {// 获得指定的音频格式audioFormat = getAudioFormat();DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, audioFormat);targetDataLine = (TargetDataLine) AudioSystem.getLine(dataLineInfo);// Create a thread to capture the microphone// data into an audio file and start the// thread running. It will run until the// Stop button is clicked. This method// will return after starting the thread.flag = true;new CaptureThread().start();} catch (Exception e) {e.printStackTrace();} // end catch}// end captureAudio methodclass CaptureThread extends Thread {public void run() {@SuppressWarnings("unused")AudioFileFormat.Type fileType = null;File audioFile = new File(filePath);boolean has= new File(filePath).exists();if(has) {audioFile.delete();}fileType = AudioFileFormat.Type.WAVE;//声音录入的权值int weight = 2;//判断是否停止的计数int downSum = 0;ByteArrayInputStream bais = null;ByteArrayOutputStream baos = new ByteArrayOutputStream();AudioInputStream ais = null;try {targetDataLine.open(audioFormat);targetDataLine.start();byte[] fragment = new byte[1024];ais = new AudioInputStream(targetDataLine);while (flag) {targetDataLine.read(fragment, 0, fragment.length);//当数组末位大于weight时开始存储字节(有声音传入),一旦开始不再需要判断末位if (Math.abs(fragment[fragment.length-1]) > weight || baos.size() > 0) {baos.write(fragment);System.out.println("守卫:"+fragment[0]+",末尾:"+fragment[fragment.length-1]+",lenght"+fragment.length);//判断语音是否停止if(Math.abs(fragment[fragment.length-1])<=weight){downSum++;}else{System.out.println("重置奇数");downSum=0;}//计数超过20说明此段时间没有声音传入(值也可更改)if(downSum>20){System.out.println("停止录入");break;}}}//取得录音输入流audioFormat = getAudioFormat();byte audioData[] = baos.toByteArray();bais = new ByteArrayInputStream(audioData);ais = new AudioInputStream(bais, audioFormat, audioData.length / audioFormat.getFrameSize());//定义最终保存的文件名System.out.println("开始生成语音文件");AudioSystem.write(ais, AudioFileFormat.Type.WAVE, audioFile);downSum = 0;stopRecognize();} catch (Exception e) {e.printStackTrace();} finally {//关闭流try {ais.close();bais.close();baos.reset();} catch (IOException e) {e.printStackTrace();}}}// end run}// end inner class CaptureThread
}

2.)接下来是阿里的语音识别的系统

package com.wqc.sound;import java.io.File;
import java.io.InputStream;import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;import com.alibaba.nls.client.protocol.InputFormatEnum;
import com.alibaba.nls.client.protocol.NlsClient;
import com.alibaba.nls.client.protocol.SampleRateEnum;
import com.alibaba.nls.client.protocol.asr.SpeechRecognizer;
import com.alibaba.nls.client.protocol.asr.SpeechRecognizerListener;
import com.alibaba.nls.client.protocol.asr.SpeechRecognizerResponse;/*** @author zhishen.ml* @date 2018-06-12*/
public class SpeechRecognizerDemo {private String appKey;private String accessToken;NlsClient client;public SpeechRecognizerDemo(String appKey, String token) {this.appKey = appKey;this.accessToken = token;//创建NlsClient实例,应用全局创建一个即可,默认服务地址为阿里云线上服务地址client = new NlsClient(accessToken);}public SpeechRecognizerDemo(String appKey, String token, String url) {this.appKey = appKey;this.accessToken = token;//创建NlsClient实例,应用全局创建一个即可,用户指定服务地址client = new NlsClient(url, accessToken);}private static SpeechRecognizerListener getRecognizerListener() {SpeechRecognizerListener listener = new SpeechRecognizerListener() {//识别出中间结果.服务端识别出一个字或词时会返回此消息.仅当setEnableIntermediateResult(true)时,才会有此类消息返回@Overridepublic void onRecognitionResultChanged(SpeechRecognizerResponse response) {//事件名称 RecognitionResultChangedSystem.out.println("name22222222: " + response.getName() +//状态码 20000000 表示识别成功", status2222222: " + response.getStatus() +//语音识别文本", result22222222: " + response.getRecognizedText());}//识别完毕@Overridepublic void onRecognitionCompleted(SpeechRecognizerResponse response) {//事件名称 RecognitionCompletedSystem.out.println("name11111111: " + response.getName() +//状态码 20000000 表示识别成功", status111111: " + response.getStatus() +//语音识别文本", result1111111: " + response.getRecognizedText());}@Overridepublic void onStarted(SpeechRecognizerResponse response) {System.out.println("task_id: " + response.getTaskId());}@Overridepublic void onFail(SpeechRecognizerResponse response) {System.out.println("task_id: " + response.getTaskId() +//状态码 20000000 表示识别成功", status: " + response.getStatus() +//错误信息", status_text: " + response.getStatusText());}};return listener;}public void process(InputStream ins) {SpeechRecognizer recognizer = null;try {//创建实例,建立连接recognizer = new SpeechRecognizer(client, getRecognizerListener());recognizer.setAppKey(appKey);//设置音频编码格式recognizer.setFormat(InputFormatEnum.PCM);//设置音频采样率recognizer.setSampleRate(SampleRateEnum.SAMPLE_RATE_16K);//设置是否返回中间识别结果recognizer.setEnableIntermediateResult(true);//此方法将以上参数设置序列化为json发送给服务端,并等待服务端确认recognizer.start();//语音数据来自声音文件用此方法,控制发送速率;若语音来自实时录音,不需控制发送速率直接调用 recognizer.sent(ins)即可recognizer.send(ins, 3200, 100);//通知服务端语音数据发送完毕,等待服务端处理完成recognizer.stop();} catch (Exception e) {System.err.println(e.getMessage());} finally {//关闭连接if (null != recognizer) {recognizer.close();}}}public void shutdown() {client.shutdown();}public static void main(String[] args) throws Exception {String appKey = null;String token = null;String url = null;SpeechRecognizerDemo demo = null;// while (true) {
//              EngineeCore engineeCore = new EngineeCore();
//
//              engineeCore.startRecognize();String filePath = "E:\\1jAVE\\ECLIPSE\\obj\\nls-example-recognizer\\src\\main\\resources\\nls-sample-16k.wav";File audioFile = new File(filePath);//boolean has= new File(filePath).exists();//if (has) {if (args.length == 2) {appKey = args[0];token = args[1];//default url is wss://nls-gateway.cn-shanghai.aliyuncs.com/ws/v1demo = new SpeechRecognizerDemo(appKey, token);} else if (args.length == 3) {appKey = args[0];token = args[1];url = args[2];demo = new SpeechRecognizerDemo(appKey, token, url);} else {System.err.println("SpeechRecognizerDemo need params(url is optional): " +"<app-key> <token> [<url>]");System.exit(-1);}AudioInputStream ins=AudioSystem.getAudioInputStream(audioFile);// InputStream ins = SpeechRecognizerDemo.class.getResourceAsStream("/voice_cache.wav");if (null == ins) {System.err.println("open the audio file failed!");System.exit(-1);}demo.process(ins);demo.shutdown();}//}// }}

上面两个子项目是以独立文件保存和读取的形式来实现的

接下来是pom文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.10.RELEASE</version><relativePath>../pom.xml</relativePath></parent><groupId>com.wqc</groupId><artifactId>aliAI-sound-spring</artifactId><version>1.5.10.RELEASE</version><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>com.alibaba.nls</groupId><artifactId>nls-sdk-recognizer</artifactId><version>2.1.0</version></dependency><dependency><groupId>ch.qos.logback</groupId><artifactId>logback-classic</artifactId><version>1.0.13</version></dependency><!-- 语音读书 --><dependency><groupId>com.hynnet</groupId><artifactId>jacob</artifactId><version>1.18</version></dependency><!-- 读取xml --><dependency><groupId>jaxen</groupId><artifactId>jaxen</artifactId><version>1.1-beta-11</version><exclusions><exclusion><groupId>xerces</groupId><artifactId>xercesImpl</artifactId></exclusion></exclusions></dependency><dependency><groupId>dom4j</groupId><artifactId>dom4j</artifactId><version>1.6.1</version></dependency><dependency><groupId>com.ibm.icu</groupId><artifactId>icu4j</artifactId><version>3.8</version></dependency><dependency><groupId>xerces</groupId><artifactId>xmlParserAPIs</artifactId><version>2.6.2</version></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><version>2.3.1</version><configuration><archive><manifest><addClasspath>true</addClasspath></manifest><manifestEntries><Premain-Class>com.xzq.test.PreAgent</Premain-Class></manifestEntries></archive></configuration></plugin></plugins></build>
</project>

干货 应用阿里AI一句话识别 java 实现语音实时识别相关推荐

  1. python百度语音实时识别成文字

    python 实现百度AI语音实时识别成文字 百度AI接口https://console.bce.baidu.com/ai/?_=1559654571070&fromai=1#/ai/spee ...

  2. NLP之ASR:基于python和机器学习算法带你玩转的语音实时识别技术

    NLP之ASR:基于python和机器学习算法带你玩转的语音实时识别技术 导读 带你玩转python实现的语音实时识别技术(包括音频混音.回声消除.噪音滤除.杂音消除.静音检测等方法) 视频观看: 软 ...

  3. 全球冠军!阿里AI图像识别竞赛:1600万图片识别率高达82.54%

    近日,第三届图像识别竞赛WebVision中,阿里AI击败了全世界150多支参赛队伍,获得冠军. WebVision由谷歌.美国卡耐基梅隆大学.苏黎世联邦理工大学等机构联合全球视觉技术领域顶级学术会议 ...

  4. 语音性别识别_语音识别识别性别_语音文字识别 - 云+社区 - 腾讯云

    广告关闭 腾讯云双11爆品提前享,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高满返5000元! 一句话识别,错误码,产品简介,产品优势,应用场景,计费概述,购买方式,欠费说明,功 ...

  5. python百度语音实时识别成文字_python 语音合成

    0树莓派 Python 使用 mpg123 播放声音 安装 mpg123 执行命令:sudo apt-get install mpg123 播放声音 import os os.system('mpg1 ...

  6. python百度语音实时识别成文字_python 上传百度语音识别+文字返回结果

    1文字生成语音 #!/usr/bin/python3 import urllib.request import requests#导入requests库 import urllib import js ...

  7. 【情感识别】SVM语音情感识别(带面板)【含GUI Matlab源码 876期】

    ⛄一.SVM语音情感识别简介 0 引 言 语音情感识别是当前研究热点,在人机交互(Human-Computer Interaction,HCI)领域的应用价值日益突显.在今天的HCI系统中,机器可以通 ...

  8. android实时识别,Android-中国象棋-实时识别-实时AI

    中国象棋人机界面 中国象棋场景识别 1.实时读取摄像头,显示图片 2.将图片数据传给ndk-c++ 3.caffe or tensorflow ? 3.caffe / tensorflow 移植至 a ...

  9. 小程序AI初体验 | 做一款实时识别车辆报价的小程序

最新文章

  1. 基于OpenCV的显著图绘制
  2. 选频放大电路对于150kHz导航信号进行放大检波
  3. oracle远程连接串,oracle远程连接
  4. 【pmcaff】pm怎么跟妈妈解释自己是做什么的
  5. Python-OpenCV学习--电脑外接摄像头实时采集FAST角点并显示
  6. 构建之法 第三次心得
  7. 如何使用 git 更新branch到master最新状态
  8. php 检测编码函数,自己写了一个php检测文件编码的函数
  9. vue接收json数据_Vue之使用ajax获取json数据,并用v-for循环显示在表格中
  10. R语言基础入门(6)之向量下标和子集
  11. python 批量增加文件前缀_用python批量提取视频中的音频文件
  12. 剑指offer——面试题32:从1到n整数中1出现的次数
  13. python安装包打不开
  14. 2018年华为数通技术大赛复赛拓扑题
  15. 【转】WIFI-Direct(Wifi直连)、AirPlay、DLAN、Miracast功能介绍
  16. VS | 设置头文件包含目录(无法打开包括文件,No such file or directory的解决)
  17. DeepFool对抗算法_学习笔记
  18. 互联网产品经理的职责
  19. lol比尔吉沃特服务器未响应,LOL比尔吉沃特9月30日网络波动公告 引起卡机掉线丢包状况...
  20. 【Halcon】线阵相机标定

热门文章

  1. OLED屏幕和LCD屏幕的区别与优劣
  2. 华师计算机学院2014级,华师,新生早知道
  3. 中信涂猪android抓包,玩卡计划 篇二:中信《鼠来宝》规则攻略,珠光宝气之后的活动!还记得去年的涂猪吗?...
  4. LAMP系统构建论文
  5. Neo4j 之 Cypher 语法(1)
  6. 服务端渲染(SSR) 通用技术解决方案
  7. python爬虫成长之路(一):抓取证券之星的股票数据
  8. C#写Windows Service(windows服务程序)
  9. 98. 我说说你对Java GC机制的理解?
  10. 【Stephen Boyd】【2009】凸优化