当用户访问网站时,如何调用计算机内置的麦克风打开?我听说有很多不同的方法可以这样做,但我想就最好的方法提出一些建议。
为了提供一个元级视图,我打算让麦克风拾取噪音并将其显示为图形均衡器(各种类型)但不记录它。
代码表示赞赏!
答案 0 :(得分:1)
答案 1 :(得分:1)
对于我的flash麦克风,我使用此课程
import org.bytearray.micrecorder.MicRecorder;
import org.bytearray.micrecorder.encoder.WaveEncoder; import 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)
}
答案 2 :(得分:0)
您希望查看Microphone class以从麦克风中拾取声音,并在computeSpectrum() method处计算均衡器的频率值。
以下是您尝试做的一个示例,来自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);
}
}}