JAVA做的语音识别

zjx8613 2011-06-09 09:55:21
我想用java实现一个 语音识别的软件。比如我说一句‘hello’,软件就会采集我说话的特征值,并记录下来,并输出相应值。当别人说‘hello’的时候,采集其特征值,并与我的比较,相同就通过,不同就继续输入。声音的采集主要通过麦克风实现。
...全文
6410 41 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
41 条回复
切换为时间正序
请发表友善的回复…
发表回复
SteveJXH 2013-11-26
  • 打赏
  • 举报
回复
引用 39 楼 trukey 的回复:
大侠你好,想请教你一个问题。 “ 录音的时候,每次读取数据是存放在buffer这个字节数组之中的,再把它输出。而你,是要识别的话,就是从这个数组中提取信息。那么这个数组的结构是什么样的呢。对这个程序而言,采用16位双声道录音,那么这个数组,每2位拼起来,是一个采样值,这个值即是声音的响度。将2个字节视为一个单位的话,由于是双声道,就是说,两个单位一组,一个是左声道,一个是右声道,交替录入的。 ” 在论坛看过你的贴子,但不太明白。 我现在要做一个计算心跳频率的程序,声音录到了,但得到的buffer这个字节数组后,不知道下一步怎么做,求指导,谢谢。
请问这位大侠如何得到buffer字节数组?
SteveJXH 2013-11-26
  • 打赏
  • 举报
回复
@wenbodong #22 22楼的大侠,你的语音的回放功能在底下可拉动的条拉到最头之后可以实现完整回放,你可以尝试着修改相应的部分,另,我觉着这个声音的播放和声波的产生还是有一定的滞后,不知能否烦劳大侠看看如何解决?
trukey 2013-10-30
  • 打赏
  • 举报
回复
大侠你好,想请教你一个问题。 “ 录音的时候,每次读取数据是存放在buffer这个字节数组之中的,再把它输出。而你,是要识别的话,就是从这个数组中提取信息。那么这个数组的结构是什么样的呢。对这个程序而言,采用16位双声道录音,那么这个数组,每2位拼起来,是一个采样值,这个值即是声音的响度。将2个字节视为一个单位的话,由于是双声道,就是说,两个单位一组,一个是左声道,一个是右声道,交替录入的。 ” 在论坛看过你的贴子,但不太明白。 我现在要做一个计算心跳频率的程序,声音录到了,但得到的buffer这个字节数组后,不知道下一步怎么做,求指导,谢谢。
水上冰石 2013-08-18
  • 打赏
  • 举报
回复
引用 15 楼 zjx8613 的回复:
先学习学习 因为原来没接触过 不知道如何下手呀。 你会用sphinx2-0.1 这个我看网上说事JAVA里面专门做语音的 但是下了也不知道该怎么用压
sphinx4正在试,能调通demo,就是识别率很低,我觉得我哪个特征文件没有配置好,就是不知道是什么没配好,有做这块的吗,给个指导
水上冰石 2013-08-17
  • 打赏
  • 举报
回复
帮顶啊,我在做java语音评分程序,有朋友会这个的加个qq:508651685
xu20101010 2012-07-18
  • 打赏
  • 举报
回复
代码要有注释呀
lunzuo 2012-06-29
  • 打赏
  • 举报
回复
好东西 学习啊
leiwuluan 2011-10-14
  • 打赏
  • 举报
回复
33楼有什么进展啊、、、分享下啊。
zjx8613 2011-10-13
  • 打赏
  • 举报
回复
非常感谢 22楼
leiwuluan 2011-10-13
  • 打赏
  • 举报
回复
去除噪音----byte (也就是不是我们说的话的) abs(80)还是多少、、
leiwuluan 2011-10-13
  • 打赏
  • 举报
回复
我也关注一下、、、提取语音的特征(样本)----->存库------->(语音命令)----->库对比。(特定人识别)


谁有idea 提取语音特性。

陈砚羲 2011-07-01
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 wenbodong 的回复:]
声音识别是一个专门的技术,其实就是对声音波形的判断。如果你想用Java实现的话,那你必须先对Java的声音输入输出的操作有基本的了解。下面是一个简单的录音并输出的程序。录音的时候,每次读取数据是存放在buffer这个字节数组之中的,再把它输出。而你,是要识别的话,就是从这个数组中提取信息。那么这个数组的结构是什么样的呢。对这个程序而言,采用16位双声道录音,那么这个数组,每2位拼起来,是一个采样值……
[/Quote]
看了一下,写得真好,请问一下录音后输出在哪啊?方便的话请加QQ313158469,求教一下?
谢谢啦!
zjx8613 2011-06-28
  • 打赏
  • 举报
回复
非常感谢 呵呵。。。。那我要结贴了
wenbodong 2011-06-25
  • 打赏
  • 举报
回复
代码过长,只能分开贴

public void initData(){
point=new int[600];
Arrays.fill(point, 0);
number=600;
bufferAll=new byte[130*1024*1024];
bufferAllIndex=0;
vRate=120;
hRate=20;//1470
continueRecorde=false;
continueReplay=false;
jsbActive=true;
}
public void play() {

try {
AudioFormat audioFormat =
// new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100F,
// 8, 1, 1, 44100F, false);
new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,44100F, 16, 1, 2,
44100F, true);
DataLine.Info info = new DataLine.Info(TargetDataLine.class,
audioFormat);
TargetDataLine targetDataLine = (TargetDataLine) AudioSystem.getLine(info);
targetDataLine.open(audioFormat);
SourceDataLine sourceDataLine;
info = new DataLine.Info(SourceDataLine.class, audioFormat);
sourceDataLine = (SourceDataLine) AudioSystem.getLine(info);
sourceDataLine.open(audioFormat);
targetDataLine.start();
sourceDataLine.start();
FloatControl fc=(FloatControl)sourceDataLine.getControl(FloatControl.Type.MASTER_GAIN);
double value=2;
float dB = (float)(Math.log(value==0.0?0.0001:value)/Math.log(10.0)*20.0);
fc.setValue(dB);
int nByte = 0;
final int bufSize=256;
byte[] buffer = new byte[bufSize];
new Thread(){
public void run(){
while(true){
if(!continueRecorde){
try{
Thread.sleep(50);
}catch(InterruptedException ie){}
continue;
}
synchronized(bufferAll){
if(600*hRate*2<bufferAllIndex){
int beginIndex=bufferAllIndex-600*hRate*2;
for(int i=0;i<600;i++,beginIndex+=2*hRate){
int hBit=bufferAll[beginIndex];
int lBit=bufferAll[beginIndex+1];
point[i]=hBit<<8|lBit;
point[i]/=vRate;
point[i]+=panHeight/2;
}
number=600;
pan.repaint();
}
else{
int beginIndex=0;
number=bufferAllIndex/hRate/2;
for(int i=0;i<number;i++,beginIndex+=2*hRate){
int hBit=bufferAll[beginIndex];
int lBit=bufferAll[beginIndex+1];
point[i]=hBit<<8|lBit;
point[i]/=vRate;
point[i]+=panHeight/2;
}
pan.repaint();
}
int length=bufferAllIndex/hRate/2;
if(length>600){
timeLocationScrollBar.setMaximum(length-600);
timeLocationScrollBar.setValue(length-600);
}
}
try{
Thread.sleep(10);
}catch(InterruptedException ie){}
}
}
}.start();
while (nByte != -1) {
if(!continueRecorde){
try{
Thread.sleep(50);
}catch(InterruptedException ie){}
continue;
}
synchronized(bufferAll){
nByte = targetDataLine.read(buffer, 0, bufSize);
System.arraycopy(buffer, 0, bufferAll, bufferAllIndex, nByte);
bufferAllIndex+=nByte;
sourceDataLine.write(buffer, 0, nByte);
}
// try{
// Thread.sleep(10);
// }catch(InterruptedException ie){}
}
sourceDataLine.stop();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]){
new ShowWave();
}
}

真是没道理,三百行也叫长
wenbodong 2011-06-25
  • 打赏
  • 举报
回复
那针对上次给你的那个录音程序,我写了一个录音并显示波形的程序。功能如下:
1.点击“开始”开始录音并显示,点击“暂停”即可暂停录音。
2.在暂停录音的状态下,可以移动滚动条查看之前的波形,按“回放”可以回放并显示波形,回放的开始是在当前显示的最左边的波形所对应的声音(不过这里遇到一个问题,即最后一点声音回放不出来,比较奇怪,没找到原因)。
程序如下:

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.Line2D;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.TargetDataLine;
/**
* 2011-6-23 0:53:40
* @author Administrator
*/
public class ShowWave {
JFrame frame;
JPanel pan;
final int panHeight=400;
JScrollBar timeLocationScrollBar;
int point[];
int number;
byte bufferAll[];
int bufferAllIndex;
int vRate,hRate;
JButton startButton,pauseButton;
JButton replayButton,stopReplayButton;
boolean continueRecorde;
boolean continueReplay;
JPanel centerPane,buttonPane;
JSlider hSlider;
boolean jsbActive;
public ShowWave(){
initData();
frame=new JFrame("录音并显示波形");
pan=new JPanel(){
public void paint(Graphics g){
g.setColor(Color.WHITE);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
g.setColor(Color.red);
int x[]=new int[number];
for(int i=0;i<number;i++){
x[i]=i;
point[i]=panHeight-point[i];
}
g.drawPolyline(x, point, number);
// Graphics2D g2d=(Graphics2D)g;
// for(int i=0;i<number-1;i++){
// g2d.draw(new Line2D.Double(x[i], point[i], x[i+1], point[i+1]));
// }
g.setColor(Color.blue);

}
};
pan.setPreferredSize(new Dimension(600,panHeight));
timeLocationScrollBar=new JScrollBar();
timeLocationScrollBar.setOrientation(JScrollBar.HORIZONTAL);
timeLocationScrollBar.setMaximum(0);
timeLocationScrollBar.setMinimum(0);
timeLocationScrollBar.setValue(0);
timeLocationScrollBar.addAdjustmentListener(new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent e) {
if(jsbActive==false){
return;
}
synchronized(bufferAll){
int beginIndex=timeLocationScrollBar.getValue();
beginIndex=beginIndex*2*hRate;
if(beginIndex==0){
number=bufferAllIndex/hRate/2;
if(number>600){
number=600;
}
}
else{
number=600;
}
for(int i=0;i<number;i++,beginIndex+=2*hRate){
int hBit=bufferAll[beginIndex];
int lBit=bufferAll[beginIndex+1];
point[i]=hBit<<8|lBit;
point[i]/=vRate;
point[i]+=panHeight/2;
}
pan.repaint();
}
}
});
centerPane=new JPanel();
centerPane.setLayout(new BorderLayout());
centerPane.add(pan);
centerPane.add(timeLocationScrollBar,BorderLayout.SOUTH);
frame.getContentPane().add(centerPane);
startButton=new JButton("开始");
startButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
continueRecorde=true;
jsbActive=false;
}
});
pauseButton=new JButton("暂停");
pauseButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
continueRecorde=false;
jsbActive=true;
}
});
hSlider=new JSlider();
hSlider.setOrientation(JSlider.HORIZONTAL);
hSlider.setMaximum(100);
hSlider.setMinimum(1);
hSlider.setValue(hRate);
hSlider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
hRate=hSlider.getValue();
int length=bufferAllIndex/hRate/2;
length-=600;
int value=(int)((double)timeLocationScrollBar.getValue()/timeLocationScrollBar.getMaximum()*length);
jsbActive=false;
timeLocationScrollBar.setMaximum(length);
jsbActive=true;
timeLocationScrollBar.setValue(value);
}
});
replayButton=new JButton("回放");
replayButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(continueRecorde||continueReplay){
return;
}
new Thread(){
public void run(){
try{
continueReplay=true;
AudioFormat audioFormat =new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
44100F, 16, 1, 2,44100F, true);
DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
SourceDataLine sourceDataLine;
sourceDataLine = (SourceDataLine) AudioSystem.getLine(info);
sourceDataLine.open(audioFormat);
sourceDataLine.start();
FloatControl fc=(FloatControl)sourceDataLine.getControl(FloatControl.Type.MASTER_GAIN);
double value=2;
float dB = (float)(Math.log(value==0.0?0.0001:value)/Math.log(10.0)*20.0);
fc.setValue(dB);
int beginIndex=timeLocationScrollBar.getValue();
beginIndex=beginIndex*2*hRate;
int bufSize=1024;
byte buffer[]=new byte[bufSize];
while (beginIndex < bufferAllIndex && continueReplay) {
synchronized (bufferAll) {
int nByte = bufferAllIndex - beginIndex > bufSize ? bufSize : bufferAllIndex - beginIndex;
System.arraycopy(bufferAll, beginIndex, buffer, 0, nByte);
sourceDataLine.write(buffer, 0, nByte);
// System.out.println(beginIndex+" "+bufferAllIndex);
beginIndex += nByte;
if(beginIndex/2/hRate<=timeLocationScrollBar.getMaximum()){
timeLocationScrollBar.setValue(beginIndex/2/hRate);
}
}
}
sourceDataLine.flush();
sourceDataLine.stop();
sourceDataLine.close();
continueReplay=false;
}catch(Exception ee){ee.printStackTrace();}
}
}.start();
}
});
stopReplayButton=new JButton("停止回放");
stopReplayButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
continueReplay=false;
}
});
Box box=Box.createHorizontalBox();
box.add(Box.createHorizontalGlue());
box.add(startButton);
box.add(Box.createHorizontalStrut(10));
box.add(pauseButton);
box.add(Box.createHorizontalStrut(10));
box.add(hSlider);
box.add(Box.createHorizontalStrut(10));
box.add(replayButton);
box.add(Box.createHorizontalStrut(10));
box.add(stopReplayButton);
box.add(Box.createHorizontalGlue());
box.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
frame.getContentPane().add(box,BorderLayout.SOUTH);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
play();
}
wisoper 2011-06-25
  • 打赏
  • 举报
回复
路过一下,据说李开复做过语音识别
乀Lan 2011-06-25
  • 打赏
  • 举报
回复
嵌入式还是C++比较好
桃园闲人 2011-06-25
  • 打赏
  • 举报
回复
楼上的强!!!
fly的狐狸 2011-06-25
  • 打赏
  • 举报
回复
这个太牛B了 完全看不懂
mayb0218 2011-06-25
  • 打赏
  • 举报
回复
真强大啊,学习
加载更多回复(21)

62,634

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧