如何以编程方式检查应用程序是否发出某种声音? [英] How to check programmatically if an app is making a certain sound?

查看:47
本文介绍了如何以编程方式检查应用程序是否发出某种声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查应用程序是否发出某种声音.此应用仅产生一种特定的声音,因此只需检查应用中是否有任何声音的解决方案也能奏效.

I need to check if an app is making a certain sound. This app only produces a single specific sound, so a solution that simply checks if there's any sound whatsoever from the app will also work.

我不需要找出哪个应用发出声音或类似的东西.我知道应该产生声音的应用程序并且我知道它将是什么声音,我只需要检测播放此声音的确切时间.

I don't need to find out which app makes a sound or anything like that. I know the app that should produce a sound and I know what sound it's going to be, I simply need to detect the exact time this sound is played.

我所知道的唯一解决方案是聆听整个操作系统的音频输出,然后使用一些音频识别软件检测我的特定声音,但如果后台播放音乐或电影,它将无法正常工作,所以这不是一个选择.

The only solution I know of is to listen to the audio output for the whole OS and then detect my specific sound with some audio recognition software, but it won't work properly if there's music or a movie playing on the background, so it's not an option.

我需要一个通过 WinAPI 方法来实现的解决方案.语言在这里不是很重要 - 我可以使用 C#、javascript、Python 或其他语言.我只需要找出如何提取 Windows 7 中特定应用程序产生的声音的一般方法.

I need a solution to do it via WinAPI methods. The language isn't very important here - I can use C#, javascript, Python or another language. I just need to find out a general approach on how to extract sound produced by a specific application in Windows 7.

推荐答案

您是否看过类似主题的 SO 答案,其中包含一堆用于 IAudioSessionManager2 和相关 API:控制应用程序的卷:按进程ID

Have you looked at SO answer on similar topic with a bunch of useful .Net wrappers for IAudioSessionManager2 and related API: Controlling Application's Volume: By Process-ID

我认为

  1. 通过进程名称查找IAudioSession
  2. 通过IAudioSessionEvents
  3. 订阅其事件
  4. 监听 OnStateChanged 事件

应该为你做.

并且不要忘记您应该在非 UI 应用程序中发送可能需要一些显式代码的 Windows 消息.在 UI 应用程序中,这就是 Application.Run 在内部所做的.

And don't forget that you should pump Windows messages which might require some explicit code in non-UI applications. In UI applications this is what Application.Run does internally anyway.

这篇关于如何以编程方式检查应用程序是否发出某种声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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