C# WinForms 应用程序显示播放和录制声音的波形
我希望编写一个可以播放 WAV 文件的 C# WinForms 应用程序。播放文件时,它会显示波形(类似于示波器)。
同时,用户可以通过麦克风录制声音,尝试跟随播放的原始声音(如卡拉 OK)。该程序实时显示录制声音的波形,因此可以从原始波形显示中看到比较 波形文件和用户录制的波形文件。比较将根据原始声音和录制声音的时间差(延迟)进行。波形显示不必非常先进(无需剪切、复制或粘贴);只要能够通过时间线看到它就足够了。
我希望这已经足够清楚了。如果不清楚,请随时要求更多说明。非常感谢。
I wish to write a C# WinForms application that can play a WAV file. While playing the file, it shows a waveform (similar to an oscilloscope).
At the same time, a user can record sound via the microphone, attempting to follow the original sound played (like a karaoke). The program displays the waveform of the recorded sound real-time, so comparisons can be seen from the waveform display of the original
wave file and the recorded one by the user. The comparisons will be done as in the difference in time (the delay) of the original and recorded sound. The waveform displays don't have to be very advanced (there is no need for cut, copy or paste); just being able to see it with a timeline would suffice.
I hope this is clear enough. Please do not hesitate to ask for more clarification if it's not clear. Thank you very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 C# 做您想做的事情,但它不会像您想象的那样工作。录音在示波器类型显示器中的外观与录音在人耳中的声音实际上没有任何关系。因此,举例来说,如果我向您展示示波器显示屏上显示的两个 WAV 文件,并告诉您其中一个录音是大号演奏的录音,另一个录音是一个人说话的句子,您将无法仅从外观上知道哪个是哪个。对他们。
如果您想将用户的声音与预先录制的 WAV 进行比较,您必须变得更加复杂,对两者进行 FFT 分析并比较频谱,但即使这样也无法真正实现您想要做的事情。
更新:经过一番思考,我认为我并不完全同意我的上述说法。如果您想要做的是使用示波器类型的效果来比较 WAV 和人声的音调(或频率),那么您想要做的可能会有所帮助。如果您将示波器调整为一次显示相对较少数量的波长(例如 20 个),用户将能够快速看到提高或降低音调的效果。
我有一个大约 2 年前编写的小型 C# 应用程序示例,它执行类似的操作,只是它显示 FFT 生成的摄谱仪而不是示波器(区别基本上在于摄谱仪显示频域信息,而示波器显示频域信息)显示时域信息)。它是实时的,因此您可以对着麦克风说话/唱歌/进行任何操作,并观察光谱仪的动态变化。
如果您愿意,我可以将其挖掘出来并在此处发布代码。或者,如果您想要自己完成这一切的乐趣,我可以发布一些指向您需要的代码资源的链接。
You can do what you want with C#, but it isn't going to work like you think. There is effectively no relationship at all between how a recording looks in an oscilloscope-type display and how that recording sounds to a human ear. So, for example, if I showed you two WAV files displayed in an oscilloscope display and told you that one recording was of a tuba playing and the other was of a person speaking a sentence, you would have no idea which was which just from looking at them.
If you want to compare a user's sounds to a pre-recorded WAV, you have to get more sophisticated and do FFT analysis of both and compare the frequency spectra, but even that won't really work for what you're trying to do.
Update: after some thought, I don't think I fully agree with my above statements. What you want to do might sort of work if what you want to do is to use the oscilloscope-type effect to compare the pitch (or frequency) of the WAV and the person's voice. If you tuned the oscilloscope to show a relatively small number of wavelengths at a time (like 20, maybe), the user would be able to quickly see the effect of raising or lowering the pitch of their voice.
I have a small sample C# app that I wrote about 2 years ago that does something kind of like this, only it displays an FFT-produced spectrograph instead of an oscilloscope (the difference is basically that a spectrograph shows frequency-domain information while an oscilloscope shows time-domain information). It's realtime, so you can talk/sing/whatever into a microphone and watch the spectrograph change dynamically.
I can dig this out and post the code here if you like. Or if you want the fun of doing it all yourself, I can post some links to the code resources you'd need.
NAudio 库 拥有大量功能,可以(可能)满足您的需要。我过去曾使用它进行一些简单的操作,但它比我需要使用的功能强大得多。
The NAudio library has plenty of functionality that will (possibly) give you what you need. I've used it in the past for some simple operations, but it is much more powerful than I've had need to use.
@ZombieSheep
Naudio 确实很有用,但它也有局限性。例如,对波形显示没有太多控制,无法清除并重新绘制。此外,如果太长,则无法向后滚动以查看前面部分的波形。另一件事是它只适用于播放声音,但不适用于录制声音。
谢谢。
@ZombieSheep
Naudio is indeed useful, but it has limitations. For example, there is not much control over the waveform display, it cannot be cleared and redrawn again. Besides, if it gets too long its impossible to scroll back to see the waveform in the front part. One more thing is that it only works with playing the sound but does not work with recording the sound.
Thank you.