音频输入编程
我所玩的内容超出了我通常所做的编程范围,所以我想在浪费更多时间之前先问一下。
所以基本上我有一个按钮(通常在计算机的开/关开关上找到),并利用我不太丰富的电子知识将其连接到标准音频线(当然连接到我的计算机音频插孔)。通过 Audacity,我发现当我单击按钮时,会生成并拾取音频波形。
这些都是非常基本的东西,我把 Arduino 留在了我父母的地方,所以在绝望中我决定使用我的声卡作为微控制器。
无论如何,我相信你们都知道我要说的是什么。 我怎样才能编写一个在命令提示符上运行的小应用程序(用于测试)并作为后台进程来监视和处理来自输入的信息以执行某些任务(例如锁定我的计算机或打开 Firefox 等...... .)?
我使用 Java 作为我的计算学位的一部分(我们仍在学习非常基本的东西......因此提出了这个问题),并且每天也在工作中使用 PHP,所以如果我有的话,我不介意学习一门新语言到。
What im playing around with is out of the scope of the usual programming I do so I thought I would ask before I waste more time.
So basically I have a button (usually found on a computers ON/OFF switch) and using my not-so vast knowledge of electronics I have connected it to a standard audio cable (which is of course connected to my computers audio in jack). Through Audacity I have found that when I click the button an audio wave form is generated and picked up.
This is all very basic stuff, I left my Arduino back at my parents place so In desperation I have decided to use my sound card as a micro-controller.
Anyway I'm sure you all know where I am going with this.
How can I get to programming a little app that runs on Command Prompt(For testing) and as a background process that will monitor and process the information coming from the input to do certain task (Like locking my computer or opening up Firefox etc...)?
I work with Java as part of my Computing Degree(We are still learning very basic stuff... hence the question) and also work with PHP on a daily basis for work, so I don't mind learning a new language if I have to.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最终自己解决了这个问题。基本上,它就像监听输入线然后在音频幅度达到一定量时运行一个方法一样简单。通过测试我还发现,当按下按钮时,测量到的幅度为负数,而当释放按钮时,测量到的幅度为正。这意味着您可以为这些单独的事件编写代码,如果您足够聪明,您还可以使用间隔计时器添加按下按钮时的事件。
无论如何,这里是代码(不幸的是我没有时间评论它):
AudioInputButton.java
AudioInputButtonTester.java
我打算将各种按钮状态转换为事件,所以您可以在测试器类中为它们编写代码,但现在是凌晨 2:30,如果您确实想分离逻辑,创建一个用您自己的代码扩展 AudioInputButton 的新按钮类。
I ended up figuring this one out for myself. Basically its as easy as listening to the input line then running a method if the amplitude of the audio gets gets to a certain amount. Through testing I also found that the amplitude is measured in negative numbers when the button is clicked down and a positive amplitude is registered when the button is released. That means you can write code for those individual events and if you are smart enough you can also add an event for when the button is held down by using an interval timer.
Anyway here is the code (Unfortunately I have not had the time to comment it):
AudioInputButton.java
AudioInputButtonTester.java
I was going to turn the various button states into events so that you can write your code for them in the tester class but its 2:30 am and if you really want to separate your logic that create a new button class that extends AudioInputButton with your own code.
我认为,可以通过使用 COM 端口 来标准化或简化此任务。
看看这些例子
http://www.java2s.com/Code/Java/Development -Class/COM-Port.htm
http://java.sun.com/developer/Books/javaprogramming/cookbook/11.pdf
如果您想使用音频输入插孔(麦克风输入端口)执行任务,则必须检查声音幅度的输入电平并根据强度级别完成任务。为此,您必须了解 JAVA 中的多线程和录音
I think , this task can be standardized or simplified by using COM port.
Check out these examples
http://www.java2s.com/Code/Java/Development-Class/COM-Port.htm
http://java.sun.com/developer/Books/javaprogramming/cookbook/11.pdf
If you want to do your task by using audio-in jack (Microphone input port), you have to check the input level of sound amplitude and do your task according to the intensity level. For this you have to get idea of multi-threading and recording sound in JAVA