我有带有 TRS 连接器的红外传感器,我可以将遥控器信号录制成音频。
现在我想用电视遥控器控制我的电脑,但我不知道如何将音频输入与预先录制的音频进行比较。但是当我意识到这些音频波只包含某种数据(二进制)后,我可以将它们转换为二进制或十六进制,因此比较容易得多。
波浪看起来就像这样:
这是:
这些是“确定”按钮的记录,有时右声道也有一些脉冲,我不知道为什么,传感器中的连接似乎可能已损坏。
好吧,没关系,无论如何
我需要 python 程序的帮助,该程序读取这些脉冲并将其从音频输入(麦克风)实时转换为二进制。
我知道这听起来像是“为我做这件事,同时我享受我的生活”,但我没有声音转换/阅读的经验......我一直在寻找用于录制和阅读音频的 python 示例,但没有成功。
I have IR sensor which have TRS connector and I can record my remotes signals into audio.
Now I want to control my computer with TV remote, but I don't have any clue how to compare audio input with pre-recorded audio. But after I realized that these audio waves contains only some kind data (binary) I can turn these into binary or hex, so it is much easier to compare.
Waves look just like this:
And this:
These are records of "OK" button, sometimes there are some impulses on right channel too and I don't know why, it seems like connections in sensor are damaged maybe.
Ok thats not matter, anyway
I need help with python program which read these impulses and turn these into binary, in realtime from audio input(mic).
I know it's sounds like "Do it for me, while I enjoy my life", but I don't have experiences with sound transforming/reading... I've looking for python examples for recording and reading audio, but unsuccessfully.
发布评论
评论(1)
如果您可以放弃实时要求,那么这很容易:只需将数据保存为 .wav 文件,然后使用 Python 的 wave 模块。
下面是如何在 Python 中读取 wav 文件的示例,
可以实时执行此操作,但比较困难,但仍然不是超级困难。对于实时情况,我使用 PyAudio,并且效果很好首先是遵循演示中的示例。在这些中,您基本上打开一个流并一次读取小块,如果您想要任何交互性,您需要在线程中执行此操作。
(另外,请注意,声卡会过滤你的音频输入,所以你看到的不会是真正的输入信号。特别是,我认为遥控器通常有 40KHz 左右的载波频率,这比人类的载波频率要高听力,所以我怀疑声卡在这个范围内是否能正常工作,尽管根据您想要做什么,它们可能就足够了。)
The this is quite easy if you can forgo the real time requirement: just save the data as a .wav file, and then read it in using Python's wave module.
Here's an example of how to read a wav file in Python,
It's possible to do this in real time, but it's harder, though still not super difficult. For real time, I use PyAudio, and a good start would be to follow the examples in the demos. In these you basically open a stream and read small chunks at a time, and if you want any interactivity, you need to do this in a thread.
(Also, note, that the sound card will filter your audio inputs, so what you see isn't going to be the true input signal. In particular, I think remote controls often have a carrier frequency around 40KHz, which is higher than human hearing, so I doubt that sound cards work well in this range, though they may be sufficient depending on what you want to do.)