gpt4 book ai didi

flash - 在 Adob​​e AIR/Actionscript 3.0 中录制 WAV - **问题**

转载 作者:行者123 更新时间:2023-12-02 23:59:51 27 4
gpt4 key购买 nike

我正在尝试从我的耳机端口直接录制到 Adob​​e Flash Builder/AIR 中的麦克风端口(使用辅助电缆),但我遇到了几个问题:

1. 与我在 iTunes 中播放的原始 MP3 文件相比,录音听起来永远不会“完整”。 PCM应该是一种未压缩的格式,所以质量应该是无损的。

2. 保存的录音(WAV)总是我录音的一半。
(例如:如果我录制一分钟,我会得到一个 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 AS 类: http://ghostcat.googlecode.com/svn-history/r424/trunk/ghostcatfp10/src/ghostcat/media/WAVWriter.as

最佳答案

是的,耳机到麦克风是问题。您仅通过耳机插孔发送一小部分数据。它已经过净化、重组、减少或节流,以使聆听体验不会中断(一个关键的体验因素)。记录下来会给你一堆泥巴。为了录制完美的音频,您必须使用音频数据本身,而不是依赖于(真诚地)朝着完美数字再现之外的其他目标努力的程序的输出。

不过,不知道为什么音频只有一半。

关于flash - 在 Adob​​e AIR/Actionscript 3.0 中录制 WAV - **问题**,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8766169/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com