简体   繁体   English

Python:将传感器数据转换为连续的调频音频

[英]Python: translate sensor data into continuous frequency modulated audio

I have a piece of python script that runs through a continuous loop (~5Hz) to obtain data from a set of sensors connected to my PC, much like a proximity sensor. 我有一段python脚本,它通过一个连续循环(〜5Hz)运行,以从连接到PC的一组传感器中获取数据,就像接近传感器一样。

I would like to translate this sensor data into audio output, using python and in a continuous manner. 我想使用python并以连续的方式将此传感器数据转换为音频输出。 That is: whilst my sensor loop is running I want to generate and play a continuous sinusoidal audio sound, of which the frequency is modulated by the sensor output (eg higher sensor value = higher frequency). 也就是说:在我的传感器回路运行时,我想生成并播放连续的正弦音频声音,其频率由传感器输出调制(例如,较高的传感器值=较高的频率)。 This is sort of the output that I want (without the GUI, of course: http://www.szynalski.com/tone-generator/ ) 这是我想要的输出(当然,没有GUI, 请访问http : //www.szynalski.com/tone-generator/

I've looked through a lot of the available packages (pyDub, pyAudio, Winsound)but all seem to solve a piece of the puzzle, either signal generation, saving or playing, but I can't seem to find out how to combine them. 我浏览了很多可用的软件包(pyDub,pyAudio,Winsound),但似乎都解决了一个难题,无论是信号生成,保存还是播放,但我似乎都找不到如何组合的方法。 。

  • It's possible to perform frequency modulation and link different frequencies together and then save them, how to play them in real-time and without clogging up my sensor 可以执行调频并将不同的频率链接在一起,然后保存它们,以及如何实时播放它们而不会阻塞我的传感器
  • It's possible to play threaded audio using WinSound -> but how to update frequence in real-time? 可以使用WinSound->播放线程音频,但是如何实时更新频率?

Or is this not a feasible route to walk on using python and should I write a script that inputs the sensor data into another more audio-friendly language? 还是这不是继续使用python的可行路线,我是否应该编写一个脚本将传感器数据输入到另一种更友好的音频语言中?

Thanks. 谢谢。

I have a piece of python script that runs through a continuous loop (~5Hz) 我有一段通过连续循环(〜5Hz)运行的python脚本

Does it not work if you just add winsound.Beep(frequency_to_play, 1) in the loop? 如果仅在循环中添加winsound.Beep(frequency_to_play,1),这不起作用吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM