Python的开放原始音频数据文件 [英] Python open raw audio data file

查看:280
本文介绍了Python的开放原始音频数据文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有扩展名为.adc这些文件。它们仅仅是原始数据文件。我可以用无畏的文件 - >导入 - >与编码原始数据符号16位和采样率16000千赫打开它们。

I have these files with the extension ".adc". They are simply raw data files. I can open them with Audacity using File->Import->Raw data with encoding "Signed 16 bit" and sample rate "16000 Khz".

我愿做同样的蟒蛇。我认为audioop模块是我需要的,但我似乎无法找到如何使用它的东西的例子就是这么简单。

I would like to do the same with python. I think that audioop module is what I need, but I can't seem to find examples on how to use it for something that simple.

主要目标是从第二个10到20秒打开该文件,并在文件中发挥了一定的位置,例如有什么事在那里为我的任务是什么?

The main goal is to open the file and play a certain location in the file, for example from the second 10 to the second 20. Is there something out there for my task ?

感谢名单提前。

推荐答案

有关打开文件,你只需要文件()
寻找一个位置,你不需要audioop:你只需要秒转换为字节,并获得该文件的所需的字节。举例来说,如果你的文件是16 kHz的16位单声道,每秒32000字节的数据。这样的第10秒是320KB到文件中。只是试图在文件中的适当位置,然后读取的字节适当数量。

For opening the file, you just need file(). For finding a location, you don't need audioop: you just need to convert seconds to bytes and get the required bytes of the file. For instance, if your file is 16 kHz 16bit mono, each second is 32,000 bytes of data. So the 10th second is 320kB into the file. Just seek to the appropriate place in the file and then read the appropriate number of bytes.

和audioop不能帮你最难的部分:即,播放音频。要做到这一点非常正确的方式取决于您的操作系统。

And audioop can't help you with the hardest part: namely, playing the audio. The correct way to do this very much depends on your OS.

编辑:对不起,我只注意到你的用户名是the​​linuxer。考虑 pyAO 从Python的Linux上播放音频。您可能需要更改样本格式播放音频--- audioop将帮助你完成这个(见ratecv,TOMONO / tostereo,lin2lin和偏置)

Sorry, I just noticed your username is "thelinuxer". Consider pyAO for playing audio from Python on Linux. You will probably need to change the sample format to play the audio---audioop will help you with this (see ratecv, tomono/tostereo, lin2lin, and bias)

这篇关于Python的开放原始音频数据文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆