简体   繁体   English

C#WinForms应用程序显示播放和录制的声音的波形

[英]C# WinForms application to display waveforms of playback and recorded sound

I wish to write a C# WinForms application that can play a WAV file. 我希望编写一个可以播放WAV文件的C#WinForms应用程序。 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). 同时,用户可以通过麦克风录制声音,尝试跟随播放的原始声音(例如卡拉OK)。 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. 非常感谢你。

You can do what you want with C#, but it isn't going to work like you think. 您可以使用C#进行所需的操作,但是它不会像您想的那样工作。 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. 因此,例如,如果我向您展示了在示波器显示屏上显示的两个WAV文件,并告诉您一个录音是吹奏大号而另一个录音是说一个人的话,那么您不会知道哪一个只是看在他们。

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. 如果要将用户的声音与预先录制的WAV进行比较,则必须变得更加复杂,并对两者进行FFT分析并比较频谱,但即使那样,对于您要尝试的操作也无法真正起作用。

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. 如果您想做的事情可能是某种工作,那就是使用示波器类型的效果来比较WAV的音调(或频率)和人的声音。 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. 如果您将示波器调谐为一次显示相对较少的波长(可能是20个),则用户将能够迅速看到提高或降低声音音高的效果。

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). 我有一个大约两年前写的小型C#应用程序示例,其功能类似,只是显示了FFT产生的光谱仪而不是示波器(基本上,光谱仪显示了频域信息,而示波器却显示了显示时域信息)。 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. 或者,如果您想自己做所有事情的乐趣,我可以发布一些指向所需代码资源的链接。

The NAudio library has plenty of functionality that will (possibly) give you what you need. NAudio库具有很多功能(可能)为您提供所需的功能。 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 is indeed useful, but it has limitations. @ZombieSheep Naudio确实有用,但是有局限性。 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. 谢谢。

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

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