gpt4 book ai didi

c# - 使用 DirectSound 向后读取声音

转载 作者:行者123 更新时间:2023-11-30 20:13:53 26 4
gpt4 key购买 nike

是否可以使用 DirectSound 的托管版本向后读取声音?如果没有,是否有另一个库可以轻松实现?

最佳答案

您可以使用 NAudio 中的 WaveFileReader 和 WaveFileWriter 类反转 WAV 文件。您需要确保使用 WaveFormat 的 BlockAlign 属性读取单个样本的所有字节(立体声 16 位音频为 4 个字节)。

    public static void ReverseWaveFile(string inputFile, string outputFile)
{
using (WaveFileReader reader = new WaveFileReader(inputFile))
{
int blockAlign = reader.WaveFormat.BlockAlign;
using (WaveFileWriter writer = new WaveFileWriter(outputFile, reader.WaveFormat))
{
byte[] buffer = new byte[blockAlign];
long samples = reader.Length / blockAlign;
for (long sample = samples - 1; sample >= 0; sample--)
{
reader.Position = sample * blockAlign;
reader.Read(buffer, 0, blockAlign);
writer.WriteData(buffer, 0, blockAlign);
}
}
}
}

关于c# - 使用 DirectSound 向后读取声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1221140/

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