Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Change Playback Speed using NAudio C#

I am implementing a Media Player and using NAudio to play my files. Is there any way to increase the playback speed like (2X or 4X) while the sound is playing. Code samples will be appreciated.

Thanks in Advance Cheers.

like image 431
wahab mehboob Avatar asked Sep 11 '25 08:09

wahab mehboob


1 Answers

NAudio does not include a ready-made component to change the speed of audio playback. However, it is possible if you create your own derived WaveStream / IWaveProvider and implement a speedup algorithm yourself. The simplest way to get a 2x or 4x speed increase is just to throw away samples. However, the quality will not be good (artefacts will be introduced), so it depends on your needs as to whether you can go with that option or not.

I have implemented variable playback speed in NAudio once myself but unfortunately I can't share the code here as it is not open source. Yuval Naveh, however has implemented variable playback speed as part of his PracticeSharp application, which uses NAudio, so you might want to check out how he has done it (I think he achieves it by wrapping SoundTouch).

like image 125
Mark Heath Avatar answered Sep 14 '25 00:09

Mark Heath