简体   繁体   English

如何改变录制声音的音调?

[英]How to change pitch of a recorded sound?

I am creating an app which record sound. 我正在创建一个记录声音的应用程序。 I am able to record and save the sound but i have to change the pitch of the recorded sound through slider. 我能够记录和保存声音,但是我必须通过滑块更改记录声音的音高。 How can I do that? 我怎样才能做到这一点? I am playing the recorded sound through media element. 我正在通过媒体元素播放录制的声音。 Here is the function to save the temporary audio file: 这是保存临时音频文件的功能:

    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();
    }

Unless you find a library with the capability built in, you will have to get access to the individual sound bytes, convert them to frames, and cursor through the frames at the rate corresponding to the desired pitch. 除非找到具有内置功能的库,否则您将必须访问各个声音字节,将其转换为帧,然后以与所需音高相对应的速率在帧中光标移动。 For example, if you want to play back at 150% speed, you would use linear interpolation to cursor through the data and provide the new values. 例如,如果要以150%的速度播放,则可以使用线性插值来游标数据并提供新值。 Example: four frames with the values 0, 0.2, 0.4, 0.6. 示例:值为0、0.2、0.4、0.6的四个帧。 Cursor through at 150% means you get the first (0) then calculate halfway between the second and third (0.3), then get the fourth (0.6), etc. Then you take that frame data and convert that back to the audio bytes. 光标以150%的速度通过意味着您获得第一个(0),然后计算第二个和第三个(0.3)之间的中间值,然后获得第四个(0.6),依此类推。然后获取该帧数据并将其转换回音频字节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM