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

player.play() doesn't correctly handle sound files with non-default format #358

Open
iarspider opened this issue Nov 12, 2022 · 7 comments
Assignees
Labels
2.0 TwitchIO 2.0 EXT: sounds

Comments

@iarspider
Copy link

I'm trying to use the new Sounds ext, and I have noticed that playing mp3 files with only one channel produces weird result - I'd say the file is played at 2x speed, or the pitch is shifted up. Converting the file to stereo fixes the issue.

MediaInfo output for mono file:

General
Complete name                            : Minion General Speech@ignore@ForMe01.mp3
Format                                   : MPEG Audio
File size                                : 25.3 KiB
Duration                                 : 1 s 619 ms
Overall bit rate mode                    : Constant
Overall bit rate                         : 128 kb/s
Genre                                    : Other

Audio
Format                                   : MPEG Audio
Format version                           : Version 1
Format profile                           : Layer 3
Duration                                 : 1 s 620 ms
Bit rate mode                            : Constant
Bit rate                                 : 128 kb/s
Channel(s)                               : 1 channel
Sampling rate                            : 44.1 kHz
Frame rate                               : 38.281 FPS (1152 SPF)
Compression mode                         : Lossy
Stream size                              : 25.3 KiB (100%)

MediaInfo output for stereo file:

General
Complete name                            : Minion General Speech@ignore@ForMe01.mp3
Format                                   : MPEG Audio
File size                                : 26.0 KiB
Duration                                 : 1 s 645 ms
Overall bit rate mode                    : Constant
Overall bit rate                         : 128 kb/s
Genre                                    : Other
Writing library                          : LAME3.100

Audio
Format                                   : MPEG Audio
Format version                           : Version 1
Format profile                           : Layer 3
Format settings                          : Joint stereo / MS Stereo
Duration                                 : 1 s 646 ms
Bit rate mode                            : Constant
Bit rate                                 : 128 kb/s
Channel(s)                               : 2 channels
Sampling rate                            : 44.1 kHz
Frame rate                               : 38.281 FPS (1152 SPF)
Compression mode                         : Lossy
Stream size                              : 25.7 KiB (99%)
Writing library                          : LAME3.100
@github-actions
Copy link

Hello! Thanks for the issue. If this is a general help question, for a faster response consider joining the official Discord Server

Else if you have an issue with the library please wait for someone to help you here.

@chillymosh chillymosh added 2.0 TwitchIO 2.0 EXT: sounds labels Nov 12, 2022
@iarspider
Copy link
Author

I don't have any 5.1 or 7.1 files, but I would guess they will also be handled incorrectly, maybe the pitch will shift down?

@iarspider iarspider changed the title player.play() doesn't correctly handle monophonic sound player.play() doesn't correctly handle sound files with non-default format Nov 20, 2022
@iarspider
Copy link
Author

iarspider commented Nov 20, 2022

So, a small update: player.play() expects the sound file to be in one specific format: 44.1 kHz, 128 kb/s, 2 channels. If any of the parameters are off, the sound will not be played correctly. I think (but don't have time to test it) that adding

-ab 128 -ar 44100 -ac 2

before pipe:1 in ffmpeg invocation here and maybe here will help.

@plomdawg
Copy link

can confirm - my mono .mp3s also play super fast

image

until I changed the lines as suggested above:

            self.proc = subprocess.Popen(
                [
                    ffmpeg_bin,
                    "-i",
                    source,
                    "-loglevel",
                    "panic",
                    "-vn",
                    "-f",
                    "s16le",
                    "-ab",
                    "128",
                    "-ar",
                    "44100",
                    "-ac",
                    "2",
                    "pipe:1",
                ],

@sockheadrps sockheadrps mentioned this issue Apr 23, 2023
7 tasks
@sockheadrps
Copy link

This is where the sample rate is hard coded. It just appears like this just isnt finished, and local files havnt been fully covered yet. Idk if theres a better way, maybe try to read in sample rate from meta data on audio, but I made a PR to at least allow you to set the values of those things that way we dont have to change the library code anymore lol

@enekochan
Copy link

The actual rate right now for the audio files must be converted to 48000 and not 44100. I don't think this is mentioned in the docs anywhere and is not trivial find this solution.

Is there a problem to merge the PR by @sockheadrps?

@IAmTomahawkx
Copy link
Member

Is there a problem to merge the PR by @sockheadrps?

I forgot it existed :)
There's a couple meta issues with the pr, but once they've been fixed it can be merged

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

No branches or pull requests

7 participants