Adobe Flash Builder/AIR에서 내 마이크 포트 (AUX 케이블 사용)에 직접 녹음하려고하는데, 몇 가지 문제가 있습니다 :Adobe AIR/Actionscript 3.0에서 WAV 녹음 - ** 문제 **
1. iTunes에서 재생중인 원래 MP3 파일과 비교하여 녹음이 "완전"으로 들리지 않습니다. PCM은 비 압축 형식이기 때문에 품질은 무손실이어야합니다.
2. 저장된 녹음 (WAV)은 항상 내가 녹음 한 길이의 절반입니다. (예 : 1 분 동안 녹음하면 0:30 wav 파일로 끝납니다. 녹음의 두 번째 절반은 거기에 없습니다)
이것은 내가 사용하고있는 코드입니다. 왜 내가이 문제를 겪고 있을지 모르는 어떤 아이디어?
import com.adobe.audio.format.WAVWriter;
import flash.display.NativeWindowSystemChrome;
import flash.events.Event;
import flash.events.SampleDataEvent;
import flash.events.TimerEvent;
import flash.filters.BitmapFilterQuality;
import flash.filters.DropShadowFilter;
import flash.media.Microphone;
import flash.media.Sound;
import flash.system.Capabilities;
import flash.utils.Timer;
import mx.controls.Alert;
import mx.core.UIComponent;
import mx.core.Window;
import mx.events.CloseEvent;
import ui.AudioVisualization;
private var shadowFilter:DropShadowFilter;
private var newWindow:Window;
// MICROPHONE STUFFZ
[Bindable] private var microphoneList:Array = Microphone.names; // Set up list of microphones
protected var microphone:Microphone; // Initialize Microphone
protected var isRecording:Boolean = false; // Variable to check if we're recording or not
protected var micRecording:ByteArray; // Variable to store recorded audio data
public var file:File = File.desktopDirectory;
public var stream:FileStream = new FileStream();
public var i:int = 0;
public var myTimer:Timer;
// [Start] Recording Function
protected function startMicRecording():void
{
if(isRecording == true) stopMicRecording();
else
{
consoleTA.text += "\nRecording started...";
consoleTA.scrollToRange(int.MAX_VALUE, int.MAX_VALUE);
isRecording = true;
micRecording = new ByteArray();
microphone = Microphone.getMicrophone(comboMicList.selectedIndex);
microphone.gain = 50;
microphone.rate = 44;
microphone.setUseEchoSuppression(false);
microphone.setLoopBack(false);
// Start timer to measure duration of audio clip (runs every 1 seconds)
myTimer = new Timer(1000);
myTimer.start();
// Set amount of time required to register silence
var userSetSilence:int;
if(splitCB.selected == true){
userSetSilence = splitNS.value; // if checkbox is checked, use the value from the numeric stepper
}
else{
userSetSilence = 2;
}
userSetSilence *= 100;
microphone.setSilenceLevel(0.5, userSetSilence); // 2 seconds of silence = Register silence with onActivity (works for itunes skip)
microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
microphone.addEventListener(ActivityEvent.ACTIVITY, this.onMicActivity);
}
}
// [Stop] Recording Function
protected function stopMicRecording():void
{
myTimer.stop(); // Stop timer to get final audio clip duration
consoleTA.text += "\nRecording stopped. (" + myTimer.currentCount + "s)";
consoleTA.scrollToRange(int.MAX_VALUE, int.MAX_VALUE);
isRecording = false;
if(!microphone) return;
microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
}
private function gotMicData(micData:SampleDataEvent):void
{
this.visualization.drawMicBar(microphone.activityLevel,0xFF0000);
if(microphone.activityLevel <= 5)
{
consoleTA.text += "\nNo audio detected"; //trace("no music playing");
consoleTA.scrollToRange(int.MAX_VALUE, int.MAX_VALUE);
}
// micData.data contains a ByteArray with our sample.
//Old: micRecording.writeBytes(micData.data);
while(micData.data.bytesAvailable) {
var sample:Number = micData.data.readFloat();
micRecording.writeFloat(sample);
}
}
protected function onMicActivity(event:ActivityEvent):void
{
//trace("activating=" + event.activating + ", activityLevel=" + microphone.activityLevel);
consoleTA.text += "\nactivating=" + event.activating + ", activityLevel=" + microphone.activityLevel;
consoleTA.scrollToRange(int.MAX_VALUE, int.MAX_VALUE);
// Mic started recording...
if(event.activating == true)
{
try{
//fs.open(file, FileMode.WRITE);
//fs.writ
}catch(e:Error){
trace(e.message);
}
}
// Mic stopped recording...
if(event.activating == false)
{
if(file)
{
i++;
myTimer.stop();
stopMicRecording();
if(deleteCB.selected == true)
{
if(myTimer.currentCount < deleteNS.value)
{
consoleTA.text += "\nAudio deleted. (Reason: Too short)";
consoleTA.scrollToRange(int.MAX_VALUE, int.MAX_VALUE);
}
else
{
writeWav(i);
}
}
else
{
writeWav(i);
}
startMicRecording();
}
}
}
private function save():void
{
consoleTA.text += "\nSaving..."; //trace("file saved!");
consoleTA.scrollToRange(int.MAX_VALUE, int.MAX_VALUE);
file = new File();
file.browseForSave("Save your wav");
file.addEventListener(Event.SELECT, writeWav);
}
public function writeWav(i:int):void
{
var wavWriter:WAVWriter = new WAVWriter();
// Set settings
micRecording.position = 0;
wavWriter.numOfChannels = 2;
wavWriter.sampleBitRate = 16; //Audio sample bit rate: 8, 16, 24, 32
wavWriter.samplingRate = 44100;
var file:File = File.desktopDirectory.resolvePath("SoundSlug Recordings/"+sessionTA.text+"_"+i+".wav");
var stream:FileStream = new FileStream();
//file = file.resolvePath("/SoundSlug Recordings/testFile.wav");
stream.open(file, FileMode.WRITE);
// convert ByteArray to WAV
wavWriter.processSamples(stream, micRecording, 44100, 1); //change to 1?
stream.close();
consoleTA.text += "\nFile Saved: " + file.exists; //trace("saved: " + file.exists);
consoleTA.scrollToRange(int.MAX_VALUE, int.MAX_VALUE);
}
PS : 나는 클래스와 표준 WavWriter을 사용하고 있습니다 : http://ghostcat.googlecode.com/svn-history/r424/trunk/ghostcatfp10/src/ghostcat/media/WAVWriter.as