3

I'm looking for a up-to-date solution to slow down / speed up the audio playback without changing the pitch (so-called "time-stretch"). The processing should be as fast as possible (audio is speech recording). Using Web Workers would be good, too.

I'm using Web Audio API. Native HTML5 is not an option for my application.

I found some solutions for time-stretching, but these are partly very old and not maintained anymore or there are no examples to use them. The list of solutions I found is from here. This post on StackOverflow is old and probably not the best solution by this time.

Is there any solution that is well implemented, stable and usable in Typescript?

julianpoemp
  • 1,965
  • 3
  • 14
  • 29
  • If you are using the Web Audio API, you may like to read about [AudioBufferSourceNode.playbackRate](https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/playbackRate) – enxaneta Dec 15 '18 at 10:39
  • @enxaneta I've read the article. I'm already using Playbackrate.value, but it changes the pitch and the duration. I need to change the duration only. – julianpoemp Dec 15 '18 at 10:45

1 Answers1

1

The easiest way without any third-party library is to use HTML5 Audio and its Audio class. It allows to change the playbackSpeed while preserving the pitch.

More Information:

https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/playbackRate

const player = new Audio();
player.src = "someURL";
player.playbackRate = 1.5;
player.play();

Why is HTML audio an option in my situation?

I was wrong, using HTML audio is an option for me. Before, I had thought I can't use HTML Audio because it offers playback positions in seconds only. Now I read the binary data from the audio file and get the duration in samples. In my application I convert the sample position to seconds automatically. That's fine and now I can use HTML Audio.

julianpoemp
  • 1,965
  • 3
  • 14
  • 29