我正在创建一个录制声音的应用程序。我能够录制并保存声音,但我必须通过 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/