Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios AVAudioFile将原始PCM编码为AAC时文件非常大_Ios_Objective C_Swift - Fatal编程技术网

Ios AVAudioFile将原始PCM编码为AAC时文件非常大

Ios AVAudioFile将原始PCM编码为AAC时文件非常大,ios,objective-c,swift,Ios,Objective C,Swift,我正在使用AVAudioFile.write将原始PCM数据缓冲区转换为aac文件。但是,该文件太大-约3KB/s(即30s音频成本约90KB)。请注意,如果我使用相同配置的AVAudioRecorder,我将获得约2KB/s(30s音频成本约60KB)。我尝试了很多设置,但都不起作用。如果有人能帮忙,我将不胜感激 编码器代码: func encodePcmToAny(buf: AVAudioPCMBuffer, outputPath: String, formatId: AudioFormat

我正在使用
AVAudioFile.write
将原始PCM数据缓冲区转换为
aac
文件。但是,该文件太大-约3KB/s(即30s音频成本约90KB)。请注意,如果我使用相同配置的
AVAudioRecorder
,我将获得约2KB/s(30s音频成本约60KB)。我尝试了很多设置,但都不起作用。如果有人能帮忙,我将不胜感激

编码器代码:

func encodePcmToAny(buf: AVAudioPCMBuffer, outputPath: String, formatId: AudioFormatID) throws {
        let settings = [
            AVFormatIDKey: Int(formatId),
            AVSampleRateKey: buf.format.sampleRate,
            AVNumberOfChannelsKey: 1,
// --- I have tried all the following without ANY change! ---
            //AVEncoderBitRateKey: 16000,
            //AVEncoderBitRatePerChannelKey: 16000,
            //AVEncoderAudioQualityKey: AVAudioQuality.min.rawValue,
            //AVEncoderBitRateStrategyKey: AVAudioBitRateStrategy_Variable,
            //AVEncoderBitDepthHintKey: 8,
            ] as [String : Any]
        
        let file = try AVAudioFile(forWriting: URL(fileURLWithPath: outputPath), settings: settings, commonFormat: .pcmFormatInt16, interleaved: false)
        
        try file.write(from: buf)
    }

需要查看创建
AVAudioPCMBuffer
的代码。现在看起来您正试图用一个缓冲区转换整个文件。@Cy-4AH是的,我首先通过file.read()创建了一个大的avaudiopcmbuffer。这是因为,我需要将aac解码成pcm,然后压缩两个文件,然后再编码回aac。所以这是一种不好的方法?谢谢是的,您没有足够的操作内存。@Cy-4AH Er。。。对不起,我不太明白。。。我的声音大约是30秒,所以以16000的采样率和浮动32它是