c# - 如何改变录制声音的音调?

标签 c# xaml audio windows-phone-8

我正在创建一个录制声音的应用程序。我能够录制并保存声音,但我必须通过 slider 更改录制声音的音高。我怎样才能做到这一点? 我正在通过媒体元素播放录制的声音。这是保存临时音频文件的函数:

    private void SaveTempAudio(MemoryStream buffer)
    {
        // Be defensive ... trust no one & nothing
        if (buffer == null)
            throw new ArgumentNullException("Attempting to save an empty sound buffer.");

        // Clean out the AudioPlayer's hold on our audioStream
         if (_audioStream != null)
        {
            AudioPlayer.Stop();
            AudioPlayer.Source = null;

            _audioStream.Dispose();
        }

        using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication()) 
        {

            if (isoStore.FileExists(_tempFileName))
                isoStore.DeleteFile(_tempFileName);

            _tempFileName = string.Format("{0}.wav", DateTime.Now.ToFileTime());

            var bytes = buffer.GetWavAsByteArray(_recorder.SampleRate);

            _audioStream = isoStore.CreateFile(_tempFileName);
            _audioStream.Write(bytes, 0, bytes.Length);

            AudioPlayer.SetSource(_audioStream);
        }
    }

    private void PlayAudioClick(object sender, RoutedEventArgs e)
    {
        AudioPlayer.Play();
    }

最佳答案

除非您找到具有内置功能的库,否则您将必须访问各个声音字节,将它们转换为帧,并以与所需音高相对应的速率在帧中移动光标。例如,如果您想以 150% 的速度回放,您可以使用线性插值来游标数据并提供新值。示例:四个帧,值为 0、0.2、0.4、0.6。光标通过 150% 意味着您获得第一个 (0),然后计算第二个和第三个 (0.3) 的中间位置,然后获得第四个 (0.6),等等。然后您获取该帧数据并将其转换回音频字节。

关于c# - 如何改变录制声音的音调?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31203466/

相关文章:

reactjs - react :播放,暂停onclick功能

c# - 未为项目设置 OutputPath 属性

c# - 如何序列化运行时将 "properties"添加到 Json

c# - 在 ASP.NET MVC3 中共享对象应用程序范围

C# : Retrieve array values from bson document

c# - 在 C# 中运行时使用外部 resx 文件(未嵌入)

c# - WPF 更改聚焦的文本框背景颜色

javascript - Chrome 64 上的音频播放暂停/停止

c# - 更新数据网格wpf中的单元格

python - 通过 Python 选择要播放的音频设备