加入收藏 | 设为首页 | 会员中心 | 我要投稿 新余站长网 (https://www.0790zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

linux上的java声音:如何从TargetDataLine中快速捕获到足以跟上

发布时间:2021-01-08 19:15:17 所属栏目:Linux 来源:网络整理
导读:我正在使用Java声音API和Java 1.7.当我在Linux上运行我的应用程序时,我很难快速地从TargetDataLine读取以跟上记录的内容(java版“1.7.0_51”,Java(TM)SE运行时环境(版本1.7.0_51-b13),Java HotSpot(TM)64位服务器VM(构建24.51-b03,混合模式),Red Hat Enterpr
副标题[/!--empirenews.page--]

我正在使用Java声音API和Java 1.7.当我在Linux上运行我的应用程序时,我很难快速地从TargetDataLine读取以跟上记录的内容(java版“1.7.0_51”,Java(TM)SE运行时环境(版本1.7.0_51-b13),Java HotSpot(TM)64位服务器VM(构建24.51-b03,混合模式),Red Hat Enterprise Linux 5).在我的Windows 7笔记本电脑上运行相同的程序时,我没有这个问题.我有点难过.

为了隔离这个问题,我编写了一个程序,它从TargetDataLine中捕获一段时间(交互式确定)并记录每次在固定字节数的阻塞读取中花费的时间,然后将它们与平均值一起打印出来读取时间,已用时间和捕获的音频时间.

我的测试程序如下:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.TargetDataLine;

/**
 * This is a test of mic capture delay for given buffer and fetch settings.
 */
public class MicCaptureDelayTest {

   /**
    * the audio format used for capturing and transmitting
    */
   private static final AudioFormat format =
         new AudioFormat(8000,16,1,true,true);

   /**
    * This is the target data line buffer size to request,in bytes.
    */
   private static final int MIC_BUFFER_SIZE = 1000;

   /**
    * This is the number of bytes to try to fetch from the target data line at a
    * time.
    */
   private static final int MIC_FETCH_SIZE = 480;

   /**
    * Searches for available mixers on the system that have a microphone.
    * @return a list of matching mixers
    */
   private static List

当我在Linux环境中运行时,大约10秒钟的录音,输出如下:

(编辑:新余站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读