php speex转码为mp3,将spx音频文件转换为mp3

博主在尝试使用C#将OGG格式的SPX音频文件转换为MP3时遇到问题。他们试图利用Naudio.Lame库的LameMP3FileWriter,但得到的输出文件只有静态噪声。另外,尝试使用NSpeex库的Mp3WriterConfig和Mp3Writer也未成功,因为这两个类不在该库中。目前不清楚'speexMsg'变量应该如何定义。博主寻求解决方案来正确地将SPX音频转换为MP3格式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我必须将spx音频文件(ogg格式)转换为mp3文件。我已经尝试了几件事,至今没有任何工作。将spx音频文件转换为mp3

我试过使用Naudio.Lame库中的LameMP3FileWriter。

private void WriteOggStreamToMp3File(Stream oggStream, string mp3FileName)

{

var format = new WaveFormat(8000, 1);

using (var mp3 = new LameMP3FileWriter(mp3FileName, format, LAMEPreset.ABR_128))

{

oggStream.Position = 0;

oggStream.CopyTo(mp3);

}

}

由于输出的mp3文件只是静态噪声,所以效果不佳。

private void WriteOggStreamToMp3File(Stream oggStream, string mp3FileName)

{

SpeexDecoder decoder = new SpeexDecoder(BandMode.Narrow);

Mp3WriterConfig config = new Mp3WriterConfig();

using (Mp3Writer mp3 = new Mp3Writer(new FileStream(mp3FileName, FileMode.Create), config))

{

int i = 0;

int bytesRead = 0;

while (i < speexMsg.SpeexData.Length)

{

short[] outData = new short[160];

bytesRead = decoder.Decode(speexMsg.SpeexData, i, speexMsg.FrameSize, outData, 0, false);

for (int x = 0; x < bytesRead; x++)

mp3.Write(BitConverter.GetBytes(outData[x]));

i += speexMsg.FrameSize;

}

mp3.Flush();

}

}

不幸的是,Mp3WriterConfig和Mp3Writer不是当前库(NSpeex)的一部分。我不知道“speexMsg”应该是什么。

所以我的问题是:如何使用c#将spx(在ogg文件中)转换为mp3?

2016-08-30

Kinetic

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值