AVAudioRecorder记录AAC / M4A [英] AVAudioRecorder record AAC/m4a
问题描述
我要记录使用AVAudioRecorder设备的音频。该文件被发送到Web服务器,我想播放生成的文件在Web浏览器。
我曾尝试在设备上设置的各种组合......似乎没有任何连接code中的文件到正确的AAC格式。
QuickTime的说,它不知道如何玩这个文件。
样code
私人无效InitializeRecordingSession(){
字符串文件名=的String.Format({0} .M4A,Guid.NewGuid());
字符串TMPDIR = Environment.GetFolderPath(Environment.SpecialFolder.Personal)+/音频;
如果(!Directory.Exists(TMPDIR))
Directory.CreateDirectory(TMPDIR);
audioFilePath = Path.Combine(TMPDIR,文件名); Console.WriteLine(音频文件路径:+ audioFilePath); VAR URL = NSUrl.FromFilename(audioFilePath);
VAR设置=新AVAudioRecorderSettings(){
AudioFormat的= AudioFormatType.MPEG4AAC,
采样率= 44100,
NumberChannels = 1,
AudioQuality = AVAudioQuality.High,
}; 记录= AVAudioRecorder.ToUrl(URL,设置超时错误); //设置记录器prepare要录制
。录音机prepareToRecord();
}
修改 - 通过把这个code中前行
=记录AVAudioRecorder.ToUrl(URL,设置超时错误);
一切工作。
NSError错误;
AVAudioSession audioSession = AVAudioSession.SharedInstance();
audioSession.SetCategory(AVAudioSession.CategoryRecord,超时错误);
audioSession.SetActive(真,超时错误);
iOS SDK中显然是愚蠢的。设置格式ID关键 kAudioFormatMPEG4AAC
是不够的,它实际上EN code中的文件;在QuickTime它将发挥,但在它的属性,你会只看到 AAC
并没有进一步的细节。输出文件的扩展名更改为 M4A
应该帮助做的伎俩,使之适用于正确的编码。
I am trying to record audio on the Device using AVAudioRecorder. That file is transmitted to a web server and I want to play that resulting file in a web browser..
I have tried various combinations of settings on the device...nothing seems to encode the file into the correct AAC format.
QuickTime says that it doesn't know how to play this file.
Sample code
private void InitializeRecordingSession() {
string fileName = string.Format("{0}.m4a", Guid.NewGuid());
string tmpdir = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/audio";
if (!Directory.Exists(tmpdir))
Directory.CreateDirectory(tmpdir);
audioFilePath = Path.Combine(tmpdir, fileName);
Console.WriteLine("Audio File Path: " + audioFilePath);
var url = NSUrl.FromFilename(audioFilePath);
var settings = new AVAudioRecorderSettings() {
AudioFormat = AudioFormatType.MPEG4AAC,
SampleRate = 44100,
NumberChannels = 1,
AudioQuality = AVAudioQuality.High,
};
recorder = AVAudioRecorder.ToUrl(url, settings, out error);
//Set Recorder to Prepare To Record
recorder.PrepareToRecord();
}
Edit-By putting this code in before the line
recorder = AVAudioRecorder.ToUrl(url, settings, out error);
Everything worked.
NSError error;
AVAudioSession audioSession = AVAudioSession.SharedInstance();
audioSession.SetCategory(AVAudioSession.CategoryRecord, out error);
audioSession.SetActive(true, out error);
The iOS SDK is apparently stupid. Setting the format ID key to kAudioFormatMPEG4AAC
is not enough for it to actually encode the file; in QuickTime it will play but in its properties you'll just see AAC
and no further details. Changing the output file extension to m4a
should help do the trick and make it apply the right encoding.
这篇关于AVAudioRecorder记录AAC / M4A的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!