【问题标题】:Noise in sending voice from android to PC over socket通过套接字从 android 向 PC 发送语音时的噪音
【发布时间】:2015-03-26 10:01:59
【问题描述】:

我正在尝试通过套接字将语音从 android 发送到 PC。我的代码正在运行,但在 PC 端我听到很多噪音,我什至无法听到任何声音。

这是我正在使用的 android 代码:

     byte buffer[]=new byte[1024];
     int buffersize = AudioRecord.getMinBufferSize(SAMPLE_RATE, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
         mic=new AudioRecord(MediaRecorder.AudioSource.MIC, SAMPLE_RATE, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, buffersize);
         mic.startRecording();
               
                  while(running){
                        count=mic.read(buffer, 0, buffer.length);
                        if(count>0){
                           OutputStream.write(buffer, 0, count);
                        }
                  }

这是 PC 代码:

    float sampleRate=44100;
    int sampleSize=16;
    int channel=1;
    boolean sign=true;
    boolean bigendian=true;
    AudioFormat format=new AudioFormat(sampleRate, sampleSize, channel, sign, bigendian);
    
    SourceDataLine voiceLine;
    DataLine.Info LineInfo=new DataLine.Info(SourceDataLine.class, format);
    if(AudioSystem.isLineSupported(LineInfo)){
        System.out.println("Line Supported...");
    }else{
        System.out.println("not supported Line...");
    }
    voiceLine = (SourceDataLine) AudioSystem.getLine(LineInfo);
    voiceLine.open(format);
    voiceLine.start();
    byte buffer[] = new byte[1024];
    inputStream=new BufferedInputStream(connection.getInputStream());    
    while(true){
                 count=inputStream.read(buffer,0,buffer.length);
                 InputStream in;
                 in=new ByteArrayInputStream(buffer);
                 AudioInputStream ais=new AudioInputStream(in, format, buffer.length /format.getFrameSize());
                 ais.read(audio, 0, count);
                 voiceLine.write(audio, 0, count);
            }

到目前为止我测试的内容:

  • 用安卓到安卓检查时语音清晰。
  • 将耳机连接到安卓手机时声音清晰。
  • 如果没有将耳机连接到安卓手机,声音不清晰(噪音很大)。

到目前为止我所尝试的:

  • 使用更少的采样率 (8000)。
  • 使用 UDP 而不是 TCP。
  • 尝试不同的缓冲区大小。

但一无所获。

【问题讨论】:

  • 有些不清楚。那么当您使用耳机并从安卓发送到 PC 时,语音是否清晰?而你的问题是当你不使用耳机并从安卓发送到 PC 时?
  • 另外,你说的android to android是什么意思?您通过 BT 将相同的内容传输到另一部 Android 手机,并且能够在 PC 上使用类似的代码进行播放?您测试事物的条件不明确。
  • 是的,它正在使用耳机工作。是的,从 android 发送到 PC。对于 android 到 android,我使用未提及的接收器代码(audioTrack 类)...
  • 因此,由于它适用于 android 到 PC,因此表明问题与麦克风有关。您是否在连接耳机的情况下同时尝试 Android 到 PC 机箱?你知道手机认为连接的是哪个麦克风吗?您可能需要尝试使用 CAMCORDER 而不是 MIC。
  • 我尝试了 CAMCORDER,但结果相同。

标签: java android sockets voice


【解决方案1】:

我最终自己解决了这个问题。

原来我不得不把它改成bigendian=false;,现在它可以工作了。

【讨论】:

    猜你喜欢
    • 2018-08-26
    • 1970-01-01
    • 2013-03-26
    • 2013-02-01
    • 1970-01-01
    • 2011-12-05
    • 2012-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多