系统设计文档模板.doc_第1页
系统设计文档模板.doc_第2页
系统设计文档模板.doc_第3页
系统设计文档模板.doc_第4页
系统设计文档模板.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Ubuntu下录音放音实现设计文档组员:何伟伦 苏耀裕目录一. 概述2二. 目的2三. 架构设计23.1. 架构分析23.2. 设计思想23.3. 架构体系21.界面设计包括,定义4个主要按钮,并将其大小位置确定,初始化是否启动此组件22.需要实例化各类监听器。33.定义按钮类,在其后面添加监听器,并设置当前按钮类其他按钮类的可用性。34录音方法与播放方法35录音数据的保存,录音方法调用其线程进行录音、46.录音文件的读取,播放方法调用其线程进行播放57.音频格式对象的创建Audioformat6一. 概述Ubuntu下的运行的录音软件是基于java语言开发的,在Ubuntu的软件中心下索安装JRE和JDK,打开终端编译class文件,再执行即可运行,软件的功能可以进行录音回放和保存当前录音。二. 目的主要用于个人学习和交流。三. 架构设计阐明进行架构设计的总体原则,如对问题域的分析方法。3.1. 架构分析 小型的播放器分为以下4个功能: 录音开始 录音停止 录音播放 录音保存 这4个功能其实是连接在一起的,录音的开始我们将一系列规定的步骤完成后,将录好的音频数据保存在数组中,再调用内部封装的方法将数组中的数据转换为音频输出流需要的数据。调用内部封装好的读取音频方法对数组进行循环读取数据,就能听到我们的声音了。3.2. 设计思想逐步分层组层解决3.3. 架构体系1.界面设计包括,定义4个主要按钮,并将其大小位置确定,初始化是否启动此组件 public static JButton btnRecord=new JButton(监听); public static JButton btnSave=new JButton(保存); public static JButton btnStop=new JButton(停止); public static JButton btnReplay=new JButton(回放); .getContentPane().add(btnRecord,South); f.getContentPane().add(tf,Center); f.getContentPane().add(btnSave,East); f.getContentPane().add(btnStop,West); f.getContentPane().add(btnReplay,North); nRecord.setEnabled(true); btnSave.setEnabled(false); btnStop.setEnabled(false); btnReplay.setEnabled(false); .setSize(240,150); f.setVisible(true);2.需要实例化各类监听器。public static MyWindowListener cls=new MyWindowListener();public tatic yActionListenerRecd Recd=new MyActionListenerRecd();public static MyActionListenerStp Stp=new MyActionListenerStp();public static MyActionListenerRep Rep=new MyActionListenerRep();public static MyActionListenerSav Sav=new MyActionListenerSav();3.定义按钮类,在其后面添加监听器,并设置当前按钮类其他按钮类的可用性。例:public static class MyActionListenerStp implements ActionListener public void actionPerformed(ActionEvent e) btnRecord.setEnabled(true); btnSave.setEnabled(true); btnStop.setEnabled(false); btnReplay.setEnabled(true); stop(); 4录音方法与播放方法/=录音方法= audioFormat = getAudioFormat(); /获得录音格式 DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, audioFormat);/取得输入设备信息,根据该对象取得输入设备信息DataLine.Info: targetDataLine = (TargetDataLine) AudioSystem.getLine(dataLineInfo);/取得输入设备,根据该设备信息,使用AudioSystem的getLine()方法取得输入设备对象 targetDataLine.open(audioFormat);/打开输入设备。按照指定的音频格式打开该设备targetDataLine: targetDataLine.start();/开始录音,启动该设备,即可开始录音: Thread captureThread = new Thread(new CaptureThread();/创建独立线程进行录音 captureThread.start(); catch(Exception e) e.printStackTrace(); System.exit(0); /=播放方法= byte audioData = byteArrayOutputStream.toByteArray();/取得录音数据 InputStream byteArrayInputStream = new ByteArrayInputStream(audioData); /转换成输入流 AudioFormat audioFormat = getAudioFormat();/取得录音格式 audioInputStream=new AudioInputStream(byteArrayInputStream,audioFormat, audioData.length / audioFormat.getFrameSize(); DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class, audioFormat);/取得输出设备信息,使用录音时相同的音频格式取得输出设备信息DataLine.Info sourceDataLine = (SourceDataLine) AudioSystem.getLine(dataLineInfo);/取得输出设备,根据输出设备信息取得输出设备对象SourceDataLine sourceDataLine.open(audioFormat);/打开输出设备,按照指定的音频格式打开该设备 sourceDataLine.start(); /创建独立线程进行播放 Thread playThread = new Thread(new PlayThread(); playThread.start(); catch(Exception e) e.printStackTrace(); System.exit(0); 5录音数据的保存,录音方法调用其线程进行录音、 private static class CaptureThread extends Thread/录音线程 byte tempBuffer=new byte10000; public void run() byteArrayOutputStream = new ByteArrayOutputStream(); totaldatasize = 0; stopCapture = false; try while(!stopCapture) /读取10000个数据 int cnt = targetDataLine.read(tempBuffer,0,tempBuffer.length); if(cnt0) /保存该数据 byteArrayOutputStream.write(tempBuffer, 0, cnt); totaldatasize += cnt; byteArrayOutputStream.close(); catch(Exception e) e.printStackTrace(); System.exit(0); 6.录音文件的读取,播放方法调用其线程进行播放private static class PlayThread extends Thread/播放线程 byte tempBuffer = new byte10000; public void run() try int cnt; /读取数据到缓存数据 while (cnt=audioInputStream.read(tempBuffer,0,tempBuffer.length)!=-1) if(cnt0) /写入缓存数据 sourceDataLine.write(tempBuffer, 0, cnt); /Block等待临时数据被输出为空 sourceDataLine.drain(); sourceDataLine.close(); catch(Exception e) e.printStackTrace(); System.exit(0); 7.音频格式对象的创建Audioformatprivate static AudioFormat getAudioFormat()/获取AudioFormat float sampleRate = 16000.0F;/ 采样频率 i

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论