麦克风检测 Actionscript 3

发布于 2024-08-06 15:08:05 字数 360 浏览 4 评论 0原文

我在检测是否检测到麦克风时遇到一些问题。我正在运行函数 Microphone.getMicrophone() ,如果没有连接麦克风,或者用户在安全面板上单击了“拒绝”,则该函数应该返回 null ,对吧?

我面临的问题是,在某些没有安装麦克风的计算机上,Microphone.getMicrophone() 仍然跟踪为 [object Microphone]

例如,假设用户没有麦克风,并且在安全面板中单击允许,我无法验证是否切换到不同的控件。

如果有人可以阐明如何检测是否未连接麦克风,那么我会洗耳恭听。

预先非常感谢, 将要

I'm having a few problems detecting whether a microphone is detected or not. I'm running the function Microphone.getMicrophone() and that should return null if there is no microphone attached, or if the user has clicked Deny on the security panel, right?

The problem I'm facing is, on some computers where there is no microphone installed, Microphone.getMicrophone() still traces out as [object Microphone].

So say for example the user doesn't have a microphone, and clicks allow in the security panel, I can't validate whether to switch to different controls.

If anybody can shed some light on how to detect if there is no microphone connected, then I'm all ears.

Many thanks in advance,
Will

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

人│生佛魔见 2024-08-13 15:08:05
var mic:Microphone          = Microphone.getMicrophone();

try {
    micName = mic.name
    trace("mic.name "+mic.name)
} catch (e:Error) {
    trace("no mic detected")
}
var mic:Microphone          = Microphone.getMicrophone();

try {
    micName = mic.name
    trace("mic.name "+mic.name)
} catch (e:Error) {
    trace("no mic detected")
}
与他有关 2024-08-13 15:08:05

好吧,我建议在连接时进行麦克风测试,记录用户的 1-2 秒并将其发送回服务器进行评估,将其发送回用户并制作一些按钮供用户在听到声音时批准。这就是 Skype 所做的,您可以添加一些奇特的控制器,以在同一测试屏幕上具有适当的噪声阈值水平和输入/输出音量等。

我不确定,但即使 getMicrophone() 返回错误/不存在的设备,它也无法正确记录它。

Well, i would recommend to make mic test upon connection, record 1-2 seconds from user and send it back to server for evaluation, send it back to user and make some button for user to approve if he heard the sound. This is what Skype do, you can add some fancy controllers to have proper noise threshold level and in/out volume and such on the same test screen.

I'm not sure but even if getMicrophone() returns false/non existent device it cannot record it properly anyway.

请止步禁区 2024-08-13 15:08:05

您可以检查 mic.activityLevel 属性来检查是否有任何麦克风级别

,如果计算机有多个麦克风,您可以在 flash.media.Microphone.names 中迭代 amic 来检查每个级别。

you can check the mic.activityLevel property to check if there is any mic level

also, if the computer has multiple mics, you can iterate amic in flash.media.Microphone.names to check each level.

并安 2024-08-13 15:08:05

我建议检查 flash.media.Microphone.names 并查看它是否为空。

I would advise to check flash.media.Microphone.names and see if it is empty.

画骨成沙 2024-08-13 15:08:05

测试麦克风的示例代码

var micIndex:String = null;//whatever mic you want to target 0,1,2
var _activityLevels:Array=[];
var _mic:Microphone = MicrophoneProvider.getMicrophone(micIndex);
var _testPassed:Boolean=false;
_mic.setLoopBack(true);
setTimeout(_timedOut, TIMEOUT_MS);//to not run forever
_checkActivity();

function _checkActivity():void{
    if (_mic) {
        var level:Number = _mic.activityLevel;
        trace("MIC _checkActivity", level, _activityLevels);
        if (level>0 && level != _activityLevels[_activityLevels.length - 1])
            _activityLevels.push(level);
        if (_activityLevels.length < 3 && !_testTimedOut)
            setTimeout(_checkActivity, 100);
        else{
            _destroy();
            _testPassed=true;
            //your mic is detected and working
        }
    }
}
function _timedOut():void{
    _testTimedOut = true;
    _destroy();
}
function _destroy():void{
            if  (_mic)
         _mic.setLoopBack(false);
    _mic=null;
}

sample code to test a microphone

var micIndex:String = null;//whatever mic you want to target 0,1,2
var _activityLevels:Array=[];
var _mic:Microphone = MicrophoneProvider.getMicrophone(micIndex);
var _testPassed:Boolean=false;
_mic.setLoopBack(true);
setTimeout(_timedOut, TIMEOUT_MS);//to not run forever
_checkActivity();

function _checkActivity():void{
    if (_mic) {
        var level:Number = _mic.activityLevel;
        trace("MIC _checkActivity", level, _activityLevels);
        if (level>0 && level != _activityLevels[_activityLevels.length - 1])
            _activityLevels.push(level);
        if (_activityLevels.length < 3 && !_testTimedOut)
            setTimeout(_checkActivity, 100);
        else{
            _destroy();
            _testPassed=true;
            //your mic is detected and working
        }
    }
}
function _timedOut():void{
    _testTimedOut = true;
    _destroy();
}
function _destroy():void{
            if  (_mic)
         _mic.setLoopBack(false);
    _mic=null;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文