当我尝试将 .WAV 文件转换为 MP3 时,AcmNotPossible 调用 acmStreamOpen

AcmNotPossible calling acmStreamOpen when I try to convert .WAV file to MP3

在这种情况下,我试图获取存储在 Azure 存储中的 .WAV 音频的 URI。这是服务代码片段:

var tempAudioUrl = _blobStorareService.UploadFileToBlob(file.FileName, file.ReadFully(), file.ContentType);
            var audioFile = await AudioConverter.ConvertToMp3Async(new Uri(string.Format(tempAudioUrl)));

            var audioUrl = _blobStorareService.UploadFileToBlob(Guid.NewGuid().ToString(), audioFile, "audio/mp3");

            _blobStorareService.DeleteBlobData(tempAudioUrl);

AudioConverter的代码class:

public static class AudioConverter
{
    public static async Task<byte[]> ConvertToMp3Async(Uri uri)
    {
        using (var client = new WebClient())
        {
            var file = await client.DownloadDataTaskAsync(uri);
            var target = new WaveFormat(8000, 16, 1);
            using (var outPutStream = new MemoryStream())
            using (var waveStream = new WaveFileReader(new MemoryStream(file)))
            using (var conversionStream = new WaveFormatConversionStream(target, waveStream))
            using (var writer = new LameMP3FileWriter(outPutStream, conversionStream.WaveFormat, 32, null))
            {
                conversionStream.CopyTo(writer);

                return outPutStream.ToArray();
            }
        }
    }
}

如果有人知道答案,我将不胜感激。

在使用 WaveFormatConversionStream 之前,您应该先使用 RawSourceWaveStream。可以帮你解决问题。

原因:if you have a 16kHz stereo file, you can't go to an 8kHz mono file in one go.

相关Post:

AcmNotPossible calling acmStreamOpen, naudio