Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change play speed? #90

Open
stheine opened this issue Jan 19, 2019 · 3 comments
Open

How to change play speed? #90

stheine opened this issue Jan 19, 2019 · 3 comments

Comments

@stheine
Copy link

stheine commented Jan 19, 2019

I am playing an audio PCM stream in javascript and would like to adjust the playback speed? how can I do this?

my relevant piece of code is:

const lame    = require('lame');
const request = require('request');
const Speaker = require('speaker');

const decoder = new lame.Decoder();
const speaker = new Speaker({
  channels:   2,
  bitDepth:   16,
  sampleRate: 44100,
  mode:       lame.STEREO,
  device:     'hw:1,0',
});

const req = request.get(url);

req
  .pipe(decoder)
  .pipe(speaker);

So, for example, can I somehow speed up the playback to 10% or 20%?

@LinusU
Copy link
Collaborator

LinusU commented Jan 19, 2019

I'm afraid that this module won't help you with this, you'll have to insert a Transform stream between lame and speaker which does this at the raw audio bytes level:

 const lame    = require('lame')
 const request = require('request')
 const Speaker = require('speaker')
+const TempoModifier = require(...)

 const decoder = new lame.Decoder()
+const tempo = new TempoModifier(1.10)
 const speaker = new Speaker({
   channels:   2,
   bitDepth:   16,
   sampleRate: 44100,
   mode:       lame.STEREO,
   device:     'hw:1,0',
 })

 const req = request.get(url)

 req
   .pipe(decoder)
+  .pipe(tempo)
   .pipe(speaker)

@stheine
Copy link
Author

stheine commented Jan 19, 2019

thanks for that info.

are you aware of any module that can be used as TempoModifier. or is that code that I/someone needs to write from scratch?

@LinusU
Copy link
Collaborator

LinusU commented Jan 21, 2019

Not aware of any such module, but could potentially exist somewhere on npm ☺️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants