audiojs / audio-play

Play audio buffer in browser/node
MIT License
60 stars 14 forks source link

mp3 playback speed is slowed down and it starts in the middle of the track #19

Open LorenzKahl opened 5 years ago

LorenzKahl commented 5 years ago

I'm on Mac OS (10.13.6) using nodejs (10.13). When I'm trying to play an mp3 file the playback speed is slowed down and it starts in the middle of the track.

I've tried multiple mp3 files from different sources - mostly all with the same outcome. This is an example which is not working for me when I download it and try to play it locally.

The only file I actually could get to play as expected was a random test I downloaded here.

Unfortunately I don't know how to determine which audio library is being used to decode the mp3 files to provide further information.

gregoryjjb commented 5 years ago

Hey, did you find a solution? I have the exact same issue, Windows 10.

derhuerst commented 5 years ago

Unfortunately I don't know how to determine which audio library is being used to decode the mp3 files [...].

It currently uses speaker underneath, which in turn uses mpg123.

gregoryjjb commented 5 years ago

Interestingly, even if I specifically install speaker, I get the message 'speaker' package not found, using 'audio-sink' instead. I don't know if that's related or not.

derhuerst commented 5 years ago

Which version of audio-play do you use? It would be best if you run npm ls to get the tree of dependencies.

gregoryjjb commented 5 years ago

audio-play version is 2.2.1.

The ls of my dependencies looks like:

audio-test@1.0.0 C:\Development\temp\audio-test
+-- audio-loader@1.0.3
| +-- audio-context@1.0.3
| +-- audio-decode@1.4.0
| | +-- audio-buffer-from@1.1.1
| | | +-- audio-buffer@4.0.4 deduped
| | | +-- audio-context@1.0.3 deduped
| | | +-- audio-format@2.3.2
| | | | +-- is-audio-buffer@1.1.0 deduped
| | | | +-- is-buffer@1.1.6 deduped
| | | | +-- is-plain-obj@1.1.0 deduped
| | | | +-- pick-by-alias@1.2.0 deduped
| | | | `-- sample-rate@2.0.1
| | | +-- is-audio-buffer@1.1.0 deduped
| | | +-- is-plain-obj@1.1.0
| | | +-- pcm-convert@1.6.5
| | | | +-- audio-format@2.3.2 deduped
| | | | +-- is-audio-buffer@1.1.0 deduped
| | | | +-- is-buffer@1.1.6 deduped
| | | | `-- object-assign@4.1.1 deduped
| | | +-- pick-by-alias@1.2.0
| | | `-- string-to-arraybuffer@1.0.2
| | |   +-- atob-lite@2.0.0
| | |   `-- is-base64@0.1.0
| | +-- audio-context@1.0.3 deduped
| | +-- audio-type@1.0.2
| | | +-- is-flac@1.1.2
| | | +-- is-m4a@1.1.0
| | | +-- is-mp3@1.1.3
| | | +-- is-ogg@1.1.2
| | | +-- is-wav@1.1.2
| | | `-- read-chunk@2.1.0
| | |   +-- pify@3.0.0
| | |   `-- safe-buffer@5.1.2 deduped
| | +-- av@0.4.9
| | | +-- coffeeify@0.6.0
| | | | +-- coffee-script@1.7.1
| | | | | `-- mkdirp@0.3.5
| | | | +-- convert-source-map@0.3.5
| | | | `-- through@2.3.8
| | | `-- speaker@0.3.1 deduped
| | +-- is-buffer@1.1.6 deduped
| | +-- mp3@0.1.0
| | +-- to-array-buffer@2.2.2
| | | +-- flatten-vertex-data@1.0.2
| | | | `-- dtype@2.0.0
| | | +-- is-blob@2.0.1
| | | `-- string-to-arraybuffer@1.0.2 deduped
| | +-- typedarray-to-buffer@3.1.5
| | | `-- is-typedarray@1.0.0 deduped
| | `-- wav-decoder@1.3.0
| +-- is-absolute@0.2.6
| | +-- is-relative@0.2.1 deduped
| | `-- is-windows@0.2.0
| +-- is-audio-buffer@1.1.0
| +-- is-buffer@1.1.6
| +-- is-relative@0.2.1
| | `-- is-unc-path@0.1.2
| |   `-- unc-path-regex@0.1.2
| +-- is-url@1.2.4
| +-- object-assign@4.1.1
| `-- request@2.88.0
|   +-- aws-sign2@0.7.0
|   +-- aws4@1.8.0
|   +-- caseless@0.12.0
|   +-- combined-stream@1.0.7
|   | `-- delayed-stream@1.0.0
|   +-- extend@3.0.2
|   +-- forever-agent@0.6.1
|   +-- form-data@2.3.3
|   | +-- asynckit@0.4.0
|   | +-- combined-stream@1.0.7 deduped
|   | `-- mime-types@2.1.21 deduped
|   +-- har-validator@5.1.3
|   | +-- ajv@6.6.1
|   | | +-- fast-deep-equal@2.0.1
|   | | +-- fast-json-stable-stringify@2.0.0
|   | | +-- json-schema-traverse@0.4.1
|   | | `-- uri-js@4.2.2
|   | |   `-- punycode@2.1.1
|   | `-- har-schema@2.0.0
|   +-- http-signature@1.2.0
|   | +-- assert-plus@1.0.0
|   | +-- jsprim@1.4.1
|   | | +-- assert-plus@1.0.0 deduped
|   | | +-- extsprintf@1.3.0
|   | | +-- json-schema@0.2.3
|   | | `-- verror@1.10.0
|   | |   +-- assert-plus@1.0.0 deduped
|   | |   +-- core-util-is@1.0.2 deduped
|   | |   `-- extsprintf@1.3.0 deduped
|   | `-- sshpk@1.15.2
|   |   +-- asn1@0.2.4
|   |   | `-- safer-buffer@2.1.2 deduped
|   |   +-- assert-plus@1.0.0 deduped
|   |   +-- bcrypt-pbkdf@1.0.2
|   |   | `-- tweetnacl@0.14.5 deduped
|   |   +-- dashdash@1.14.1
|   |   | `-- assert-plus@1.0.0 deduped
|   |   +-- ecc-jsbn@0.1.2
|   |   | +-- jsbn@0.1.1 deduped
|   |   | `-- safer-buffer@2.1.2 deduped
|   |   +-- getpass@0.1.7
|   |   | `-- assert-plus@1.0.0 deduped
|   |   +-- jsbn@0.1.1
|   |   +-- safer-buffer@2.1.2
|   |   `-- tweetnacl@0.14.5
|   +-- is-typedarray@1.0.0
|   +-- isstream@0.1.2
|   +-- json-stringify-safe@5.0.1
|   +-- mime-types@2.1.21
|   | `-- mime-db@1.37.0
|   +-- oauth-sign@0.9.0
|   +-- performance-now@2.1.0
|   +-- qs@6.5.2
|   +-- safe-buffer@5.1.2
|   +-- tough-cookie@2.4.3
|   | +-- psl@1.1.29
|   | `-- punycode@1.4.1
|   +-- tunnel-agent@0.6.0
|   | `-- safe-buffer@5.1.2 deduped
|   `-- uuid@3.3.2
`-- audio-play@2.2.1
  +-- audio-buffer@4.0.4
  | `-- audio-context@1.0.3 deduped
  +-- audio-context@1.0.3 deduped
  +-- audio-source@1.1.1
  | +-- audio-buffer@2.4.6
  | | +-- audio-context@1.0.3
  | | +-- buffer-to-arraybuffer@0.0.5
  | | +-- is-audio-buffer@1.1.0 deduped
  | | +-- is-browser@2.1.0
  | | `-- is-buffer@1.1.6 deduped
  | +-- audio-through@2.2.3
  | | +-- audio-buffer@3.2.1
  | | | +-- audio-context@1.0.3 deduped
  | | | +-- buffer-to-arraybuffer@0.0.5 deduped
  | | | +-- is-audio-buffer@1.1.0 deduped
  | | | +-- is-browser@2.1.0 deduped
  | | | +-- is-buffer@1.1.6 deduped
  | | | `-- is-plain-obj@1.1.0 deduped
  | | +-- audio-context@1.0.3 deduped
  | | +-- inherits@2.0.3 deduped
  | | +-- is-audio-buffer@1.1.0 deduped
  | | +-- is-promise@2.1.0
  | | +-- object-assign@4.1.1 deduped
  | | +-- pcm-util@2.1.0 deduped
  | | `-- performance-now@2.1.0 deduped
  | +-- inherits@2.0.3
  | +-- is-audio-buffer@1.1.0 deduped
  | `-- pull-stream@3.6.9
  +-- audio-speaker@1.5.0
  | +-- audio-sink@1.1.6
  | | +-- inherits@2.0.3 deduped
  | | `-- xtend@4.0.1
  | +-- audio-through@2.2.3 deduped
  | +-- inherits@2.0.3 deduped
  | +-- is-audio-buffer@1.1.0 deduped
  | +-- object-assign@4.1.1 deduped
  | +-- pcm-util@2.1.0
  | | +-- audio-buffer@3.2.1
  | | | +-- audio-context@1.0.3 deduped
  | | | +-- buffer-to-arraybuffer@0.0.5 deduped
  | | | +-- is-audio-buffer@1.1.0 deduped
  | | | +-- is-browser@2.1.0 deduped
  | | | +-- is-buffer@1.1.6 deduped
  | | | `-- is-plain-obj@1.1.0 deduped
  | | +-- is-audio-buffer@1.1.0 deduped
  | | +-- is-buffer@1.1.6 deduped
  | | `-- to-array-buffer@1.2.4
  | |   +-- atob-lite@1.0.0
  | |   +-- is-audio-buffer@1.1.0 deduped
  | |   `-- is-data-uri@0.1.0
  | |     `-- data-uri-regex@0.1.4
  | +-- pull-stream@3.6.9 deduped
  | +-- speaker@0.3.1
  | | +-- bindings@1.3.1
  | | +-- debug@2.6.9
  | | | `-- ms@2.0.0
  | | +-- nan@2.11.1
  | | `-- readable-stream@2.3.6
  | |   +-- core-util-is@1.0.2
  | |   +-- inherits@2.0.3 deduped
  | |   +-- isarray@1.0.0
  | |   +-- process-nextick-args@2.0.0
  | |   +-- safe-buffer@5.1.2 deduped
  | |   +-- string_decoder@1.1.1
  | |   | `-- safe-buffer@5.1.2 deduped
  | |   `-- util-deprecate@1.0.2
  | `-- web-audio-stream@3.0.1
  |   +-- audio-buffer-list@2.0.7
  |   | +-- audio-buffer@3.2.1
  |   | | +-- audio-context@1.0.3 deduped
  |   | | +-- buffer-to-arraybuffer@0.0.5 deduped
  |   | | +-- is-audio-buffer@1.1.0 deduped
  |   | | +-- is-browser@2.1.0 deduped
  |   | | +-- is-buffer@1.1.6 deduped
  |   | | `-- is-plain-obj@1.1.0 deduped
  |   | +-- audio-buffer-utils@4.3.2 deduped
  |   | +-- inherits@2.0.3 deduped
  |   | +-- is-audio-buffer@1.1.0 deduped
  |   | +-- is-plain-obj@1.1.0 deduped
  |   | +-- negative-index@1.0.3 deduped
  |   | `-- object-assign@4.1.1 deduped
  |   +-- audio-buffer-utils@4.3.2
  |   | +-- audio-buffer@3.2.1
  |   | | +-- audio-context@1.0.3 deduped
  |   | | +-- buffer-to-arraybuffer@0.0.5 deduped
  |   | | +-- is-audio-buffer@1.1.0 deduped
  |   | | +-- is-browser@2.1.0 deduped
  |   | | +-- is-buffer@1.1.6 deduped
  |   | | `-- is-plain-obj@1.1.0 deduped
  |   | +-- audio-context@1.0.3 deduped
  |   | +-- clamp@1.0.1
  |   | +-- is-audio-buffer@1.1.0 deduped
  |   | +-- is-browser@2.1.0 deduped
  |   | +-- negative-index@1.0.3 deduped
  |   | `-- typedarray-methods@1.0.1
  |   +-- audio-context@1.0.3 deduped
  |   +-- inherits@2.0.3 deduped
  |   +-- is-audio-buffer@1.1.0 deduped
  |   +-- is-plain-obj@1.1.0 deduped
  |   +-- object-assign@4.1.1 deduped
  |   +-- pcm-util@2.1.0 deduped
  |   `-- pull-stream@3.6.9 deduped
  +-- is-audio-buffer@1.1.0 deduped
  `-- negative-index@1.0.3
    `-- negative-zero@2.0.0

I'm thinking of moving my audio playing workload to an external python script or something right now, it seems like the most viable option.

LorenzKahl commented 5 years ago

Hey, did you find a solution? I have the exact same issue, Windows 10.

Hi, I gave up and resorted to using play-sound. I'm developing on a Mac but the target platform is a Raspberry Pi - play-sound works just fine on both platforms which is a huge plus for me.

gregoryjjb commented 5 years ago

I looked at play-sound and got it working but I need the ability to start playing exactly when I want to, not have it load and play in the same function call since that adds some lag. As far as I can tell this is the only Node package that can do that.

dy commented 5 years ago

Hey guys. I am going to investigate it this weekend, likely that is an issue of mp3 package. If not, there is still ongoing PR for audio-speaker, which is the second hanging update required to make it work. I'd estimate that 16-20 hours of work.

LorenzKahl commented 5 years ago

@dy much appreciated - but sure I hope you won't be spending your whole weekend on it. Cheers!

gregoryjjb commented 5 years ago

@dy same, it's no rush, I can work around it. Thanks!

prmichaelsen commented 5 years ago

I have the same issue. At first, I was delighted, because it was very fun to hear "what's new pussycat" in such a demonic form.

Ultimately, I'm going to have to try a different library, though.

BradTotaro commented 4 years ago

@gregoryjjb with play-sound, which back-end are you using, it seems that there is a preferred player for certain media types.

I'm testing on a thinkpad and a raspberry pi.

When playing MP3 with this library I hear the weird demonic version of the song, after transcode to WAV the first second is distorted, then the audio seems fine.

with play-sound on mpg123 i see inconsistent play volumes and sometimes files do not play.

gregoryjjb commented 4 years ago

@BradTotaro I never did use play-sound, as I needed the ability to load the audio into memory separately from starting playback so I could start playback instantly. I ended up writing my audio playing functionality in Python and later Rust.

fusionstream commented 2 years ago

@gregoryjjb Did you consider preconverting to wav (which seems to play fine) and then using that? I ask because I'm getting the same weirdness

gregoryjjb commented 2 years ago

@fusionstream I just revisited this problem a couple days ago and I used node-speaker and node-lame and got it to do what I wanted. If I run into issues with this setup I might try converting to WAV!