从Windows服务通过调制解调器播放语音 [英] Playing voice over modem from a Windows service
问题描述
我正在开发VB.NET Windows服务,该服务昂贵地检查BMS数据库中是否有新警报,并拨打电话远程警告操作员.我目前正在使用.NET TAPI包装器和SAPI 5.3互操作程序集,而我通过电话讲的步骤如下:
I'm developing a VB.NET Windows service which is costantly checking a BMS database for new alarms and making phone calls to warn operators remotely. I'm currently using a .NET TAPI wrapper and the SAPI 5.3 interop assembly, and the steps I'm taking to speak over the phone are:
- 初始化TAPI接口;
- 拨打运营商电话;
- 获取语音调制解调器waveOut设备ID
- 将语音输出设置为该设备ID;
- 让SAPI发挥神奇作用.
如果我将代码作为Windows控制台或窗体应用程序进行编译,则一切正常,但是,一旦我将其作为Windows服务编译并运行,则步骤5永远不会发生-语音调制解调器呼叫,但保持沉默;其他所有工作,甚至数字监控. 现在我知道Windows服务不应该与桌面交互,因此UI元素和播放声音之类的东西是不可以的,但是我正在努力寻找一种不涉及使用wave API并可以开发的替代方法在合理的时间范围内.有任何想法吗?
This is all working fine if I compile the code as a Windows console or forms application, but as soon as I compile and run it as a Windows Service, step 5 never occurs - voice modem calls but stays silent; everything else works, even digit monitoring. Now I know windows services are not supposed to interact with the desktop, so things like UI elements and playing sounds are a no-no, but I'm struggling to find an alternative which doesn't involve using the wave API and can be developed in a reasonable timeframe. Any ideas?
推荐答案
我最终在Windows Service项目中引用了Windows窗体项目,并在OnStart子目录中创建了该窗体:
I ended up referencing the windows forms project in my Windows Service project, and creating the form in the OnStart sub:
Protected Overrides Sub OnStart(ByVal args() As String)
HelperThread = New Threading.Thread(AddressOf CreateMOWindow)
HelperThread.TrySetApartmentState(Threading.ApartmentState.STA)
HelperThread.Start()
End Sub
Private Sub CreateMOWindow()
Dim frm As New AlarmVoiceTest.AlarmVoiceTest
Windows.Forms.Application.Run(frm)
End Sub
当然不会显示该表单(但是我不需要它),并且SAPI可以按预期工作.我认为这不是达到目标的最干净的方法,但是我有点没时间了:)
The form isn't showing up of course (but I don't need it to), and SAPI is working as expected. I reckon this is not the cleanest way to accomplish that, but I'm kinda running out of time :)
这篇关于从Windows服务通过调制解调器播放语音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!