内置麦克风通话

发布于 2024-10-12 23:15:26 字数 133 浏览 2 评论 0原文

如何调用计算机内置的麦克风在用户访问站点时打开?我听说有很多不同的方法可以做到这一点,但我想要一些关于最佳方法的建议。

为了提供元级视图,我计划让麦克风拾取噪声并将其显示为图形均衡器(某种),但不记录它。

代码表示赞赏!

How do you call the microphone built into a computer to turn on when a user visits a site? I've heard that there a number of different ways to do so, but I'd like some advice on the best way.

To provide a meta-level view, I'm planning on having the mic pick up noise and display it as a graphic equalizer (of sorts) but not record it.

Code is appreciated!

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

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

发布评论

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

评论(3

棒棒糖 2024-10-19 23:15:26

对于我的闪存麦克风,我使用此类

import org.bytearray.micrecorder.MicRecorder;

import org.bytearray.micrecorder.encoder.WaveEncoder;
导入 org.bytearray.micrecorder.events.RecordingEvent;

(只需谷歌即可获取代码)
就像调用它一样简单

            recorder = new MicRecorder(new WaveEncoder(),null,75,16);
    recorder.addEventListener(RecordingEvent.RECORDING, onRecording)
    recorder.addEventListener(Event.COMPLETE, onRecordComplete)

,然后您可以执行类似的操作来可视化麦克风噪声的变化。当然,您必须制作自己的 .fla 影片剪辑,以您想要的方式显示“声音”

public function onRecording(e:RecordingEvent)
{           
    var al:Number = recorder.microphone.activityLevel;
    TweenMax.to(soundMeter, .1, {scaleX:al * .01, onUpdate:onActivitylevelUpdate});//, onUpdateParams:[al]})
}       
public function onActivitylevelUpdate()
{
    xpos = speedX;
    ypos = centerY + Math.sin(angle) * amplitude
    angle += speedAngle;
    graphics.lineTo(xpos,ypos)
}

For my flash microphone i use this class

import org.bytearray.micrecorder.MicRecorder;

import org.bytearray.micrecorder.encoder.WaveEncoder;
import org.bytearray.micrecorder.events.RecordingEvent;

(just google it to get the code)
and its as easy as calling this

            recorder = new MicRecorder(new WaveEncoder(),null,75,16);
    recorder.addEventListener(RecordingEvent.RECORDING, onRecording)
    recorder.addEventListener(Event.COMPLETE, onRecordComplete)

then you can do something like this to visualize the change in microphone noise. you of course have to make your own .fla movie clip that will display the "sound" in however you want to visualize it

public function onRecording(e:RecordingEvent)
{           
    var al:Number = recorder.microphone.activityLevel;
    TweenMax.to(soundMeter, .1, {scaleX:al * .01, onUpdate:onActivitylevelUpdate});//, onUpdateParams:[al]})
}       
public function onActivitylevelUpdate()
{
    xpos = speedX;
    ypos = centerY + Math.sin(angle) * amplitude
    angle += speedAngle;
    graphics.lineTo(xpos,ypos)
}
蓝戈者 2024-10-19 23:15:26

您想要查看 Microphone 类从麦克风拾取声音,并在 computeSpectrum() 方法计算均衡器的频率值。

以下是您尝试执行的操作的示例(来自 adobe 示例):

package {
import flash.display.Sprite;
import flash.display.Graphics;
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
import flash.net.URLRequest;
import flash.utils.ByteArray;
import flash.text.TextField;

public class SoundMixer_computeSpectrumExample extends Sprite {

    public function SoundMixer_computeSpectrumExample() {
        var snd:Sound = new Sound();
        var req:URLRequest = new URLRequest("Song1.mp3");
        snd.load(req);

        var channel:SoundChannel;
        channel = snd.play();
        addEventListener(Event.ENTER_FRAME, onEnterFrame);
        channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
    }

    private function onEnterFrame(event:Event):void {
        var bytes:ByteArray = new ByteArray();
        const PLOT_HEIGHT:int = 200;
        const CHANNEL_LENGTH:int = 256;

        SoundMixer.computeSpectrum(bytes, false, 0);

        var g:Graphics = this.graphics;

        g.clear();

        g.lineStyle(0, 0x6600CC);
        g.beginFill(0x6600CC);
        g.moveTo(0, PLOT_HEIGHT);

        var n:Number = 0;

        for (var i:int = 0; i < CHANNEL_LENGTH; i++) {
            n = (bytes.readFloat() * PLOT_HEIGHT);
            g.lineTo(i * 2, PLOT_HEIGHT - n);
        }

        g.lineTo(CHANNEL_LENGTH * 2, PLOT_HEIGHT);
        g.endFill();

        g.lineStyle(0, 0xCC0066);
        g.beginFill(0xCC0066, 0.5);
        g.moveTo(CHANNEL_LENGTH * 2, PLOT_HEIGHT);

        for (i = CHANNEL_LENGTH; i > 0; i--) {
            n = (bytes.readFloat() * PLOT_HEIGHT);
            g.lineTo(i * 2, PLOT_HEIGHT - n);
        }

        g.lineTo(0, PLOT_HEIGHT);
        g.endFill();
    }

    private function onPlaybackComplete(event:Event):void {
        removeEventListener(Event.ENTER_FRAME, onEnterFrame);
    }
}}

You want to look at the Microphone class to pick up sound off the mic, and at the computeSpectrum() method to calculate frequency values for the equalizer.

Here's an example of what you're trying to do, from the adobe samples:

package {
import flash.display.Sprite;
import flash.display.Graphics;
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
import flash.net.URLRequest;
import flash.utils.ByteArray;
import flash.text.TextField;

public class SoundMixer_computeSpectrumExample extends Sprite {

    public function SoundMixer_computeSpectrumExample() {
        var snd:Sound = new Sound();
        var req:URLRequest = new URLRequest("Song1.mp3");
        snd.load(req);

        var channel:SoundChannel;
        channel = snd.play();
        addEventListener(Event.ENTER_FRAME, onEnterFrame);
        channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
    }

    private function onEnterFrame(event:Event):void {
        var bytes:ByteArray = new ByteArray();
        const PLOT_HEIGHT:int = 200;
        const CHANNEL_LENGTH:int = 256;

        SoundMixer.computeSpectrum(bytes, false, 0);

        var g:Graphics = this.graphics;

        g.clear();

        g.lineStyle(0, 0x6600CC);
        g.beginFill(0x6600CC);
        g.moveTo(0, PLOT_HEIGHT);

        var n:Number = 0;

        for (var i:int = 0; i < CHANNEL_LENGTH; i++) {
            n = (bytes.readFloat() * PLOT_HEIGHT);
            g.lineTo(i * 2, PLOT_HEIGHT - n);
        }

        g.lineTo(CHANNEL_LENGTH * 2, PLOT_HEIGHT);
        g.endFill();

        g.lineStyle(0, 0xCC0066);
        g.beginFill(0xCC0066, 0.5);
        g.moveTo(CHANNEL_LENGTH * 2, PLOT_HEIGHT);

        for (i = CHANNEL_LENGTH; i > 0; i--) {
            n = (bytes.readFloat() * PLOT_HEIGHT);
            g.lineTo(i * 2, PLOT_HEIGHT - n);
        }

        g.lineTo(0, PLOT_HEIGHT);
        g.endFill();
    }

    private function onPlaybackComplete(event:Event):void {
        removeEventListener(Event.ENTER_FRAME, onEnterFrame);
    }
}}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文