Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用python压缩音频流数据并用java解压_Java_Android_Python_Audio_Compression - Fatal编程技术网

用python压缩音频流数据并用java解压

用python压缩音频流数据并用java解压,java,android,python,audio,compression,Java,Android,Python,Audio,Compression,我成功地通过TCP将运行在raspberry pi上的python中的音频流传输到android应用程序,我尝试使用压缩,但它只处理字符串,不处理音频流中的数据(只听到噪音) 以下是我的python代码: while True: data = stream.read(CHUNKS) outData = StringIO() d = GzipFile( mode="w", fileobj = outData) d.write(data)

我成功地通过TCP将运行在raspberry pi上的python中的音频流传输到android应用程序,我尝试使用压缩,但它只处理字符串,不处理音频流中的数据(只听到噪音) 以下是我的python代码:

    while True:
      data = stream.read(CHUNKS)
      outData = StringIO()
      d = GzipFile( mode="w", fileobj = outData)
      d.write(data)
      d.close()
      conn.send((outData.getvalue()))
还有我的android代码:

    speaker = newAudioTrack(AudioManager.STREAM_VOICE_CALL,sampleRate,channelConfig,audioFormat,minBufSize,AudioTrack.MODE_STREAM);
    speaker.play();
    DataInputStream ds = new DataInputStream(connectionSocket.getInputStream());
    GZIPInputStream gzip = new GZIPInputStream(ds);
    while (true) {
    gzip.read(buffer, 0, buffer.length);
    speaker.write(buffer, 0, buffer.length);}

有人知道为什么这不起作用吗?还有,有没有其他方法可以实现我的目标?

问题可能根本不在GZIP中:

AudioTrack
仅用于此处提到的未压缩音频:

您可以尝试一下
MediaPlayer
,例如:

MediaPlayer player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource("http://...");
player.prepare();
player.start();
然而,这可能不是你所需要的,因为你正试图使用

在这种情况下,您可以使用本文中提到的临时文件

或者使用


希望这能有所帮助,祝你好运:)

如果这个答案帮助你解决了问题,请@user3461604