关于android录音实时传输出现噪音的问题

ShawnRS6 2018-05-30 11:38:28
目前在做的一个项目需要将从audiorecorder录音后得到的byte数据直接传输到后台,同时要在本地做存储。
1,本地存储:我是用RandomAccessFile的方式写入到本地文件的;
/* RIFF header */
file.writeBytes("RIFF"); // riff id
file.writeInt(0); // riff chunk size *PLACEHOLDER*
file.writeBytes("WAVE"); // wave type

/* fmt chunk */
file.writeBytes("fmt "); // fmt id
file.writeInt(Integer.reverseBytes(16)); // fmt chunk size
file.writeShort(Short.reverseBytes((short) 1)); // format: 1(PCM)
file.writeShort(Short.reverseBytes((short) CHANNELS)); // channels: 1
file.writeInt(Integer.reverseBytes(FREQUENCY)); // samples per second
file.writeInt(Integer.reverseBytes((int) (CHANNELS * FREQUENCY * BITS / 8))); // BPSecond
file.writeShort(Short.reverseBytes((short) (CHANNELS * BITS / 8))); // BPSample
file.writeShort(Short.reverseBytes((short) (CHANNELS * BITS))); // bPSample

2,传输到后台:
我也把相同的文件头写入到了数据流中,然后audiorecorder产生的byte不做处理,直接用socket流传输到后台:
/* RIFF header */
dataOutputStream.writeBytes("RIFF"); // riff id
dataOutputStream.writeInt(0); // riff chunk size *PLACEHOLDER*
dataOutputStream.writeBytes("WAVE"); // wave type

/* fmt chunk */
dataOutputStream.writeBytes("fmt "); // fmt id
dataOutputStream.writeInt(Integer.reverseBytes(16)); // fmt chunk size
dataOutputStream.writeShort(Short.reverseBytes((short) 1)); // format: 1(PCM)
dataOutputStream.writeShort(Short.reverseBytes((short) CHANNELS)); // channels: 1
dataOutputStream.writeInt(Integer.reverseBytes(FREQUENCY)); // samples per second
dataOutputStream.writeInt(Integer.reverseBytes((int) (CHANNELS * FREQUENCY * BITS / 8))); // BPSecond
dataOutputStream.writeShort(Short.reverseBytes((short) (CHANNELS * BITS / 8))); // BPSample
dataOutputStream.writeShort(Short.reverseBytes((short) (CHANNELS * BITS))); // bPSample

3,问题:
目前的情况是,本地存储的文件在播放时没有问题,声音很正常;但是传输到后台产生的文件,在播放时会出现周期性的dadada的声音。
...全文
621 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ShawnRS6 2018-05-30
  • 打赏
  • 举报
回复
是因为插入了没用的socket的截止符:\r\n,流传输时其实并不需要手动插入。

80,361

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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