mmkw43
Posts: 699
Joined: Tue Dec 24, 2013 6:18 pm

MPG321 and short files

Thu Nov 05, 2020 10:55 pm

I have a real problem. You can mimic it I suppose by calling MPG321 (and now I hear there's an MPG123? ! wtf?) and trying to play short (2 to 3 second) audio files in a script. Anyway -- this has been driving me crazy as "some" TV's will play the audio -- some do not, I have an audio extractor that plays the audio fine on a TV and doesn't extract the audio -- it's friggin crazy. Someone suggested it may be the ALC in some TV's -- my only solution is to (maybe) put a period of silence at the beginning of the file and then hope it grabs it, playing the last part of the file because this is what happens -- it completely chops off the first 2 or 3 seconds.

I'm doing a subprocess call to mpg321 /play file.mp3 and even put a slight pause before and after thinking that may be it.

I'm wondering -- is there a better way to have mog321 just sitting there and ready to play files without loading it esch time? Could that be the problem? The files are mono (using an online speech to taxt converter) -- the whole thing is driving me nuts.

Yet, if I play a whole mp4 song, no issues at all. Plays every single second of it.
If it were a TV ALC problem, it wouldn't care about the length of the audio. NIGHTMARE.

epoch1970
Posts: 6058
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: MPG321 and short files

Fri Nov 06, 2020 12:25 am

I think I would use 123 instead of its fork 321 which seems a bit dormant?
https://www.mpg123.de/links.shtml

Perhaps you can use Sox to pad silence in front of your files, or mix silence with your files. That doesn’t feel right, but I think Sox will do that for you if there is no other way.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

mmkw43
Posts: 699
Joined: Tue Dec 24, 2013 6:18 pm

Re: MPG321 and short files

Fri Nov 06, 2020 12:49 am

Ok. That's a new one -- Sox? Thanks, I'll research that -- at least you understood my question. Have you encountered other PI users with this problem I wonder? And -- tried MPG123 playing short files and just a slight improvement over MPG321 -- which in itself, when you think about it, says "something".. I'll look into Sox.

I keep thinking it needs to --

sudo mpg321 (ok, pause and get it together here) then play /mp3file ?

epoch1970
Posts: 6058
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: MPG321 and short files

Fri Nov 06, 2020 9:20 am

"Never" sudo in a script. If sudo waits for a password, you're cooked.
Give the appropriate rights to the user that runs the script instead. With debian/raspios I think adding "audio" to the list of secondary groups is enough.

I think I understand what you described, but I don't remember ever having that issue or seeing other posts on that. My linux audio days are few and far between TBH.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

mmkw43
Posts: 699
Joined: Tue Dec 24, 2013 6:18 pm

Re: MPG321 and short files

Fri Nov 06, 2020 1:57 pm

Ok -- thank you so much. I really appreciate it when someone says something that you never read anywhere like to not use sudo in a script. (I'm an amateur and hobbyist) I'm doing this --

time.sleep(2)
subprocess.call ('sudo mpg321 -q /home/pi/AUDIO/ch1.mp3',shell=True)
time.sleep(2)

It's been a while since I wrote the code for this project (2 years ago), taught myself Python and for a guy my age it's good mental exercise. May I just come out and ask, how do I set up a script so I don't need to use sudo in terminal commands? I'm not prompted for a password or anything.

I put those time.sleep pauses there thinking it would help but they don't. Plus I'm going to change mpg321 to 123.
Last edited by mmkw43 on Fri Nov 06, 2020 3:32 pm, edited 1 time in total.

User avatar
scruss
Posts: 3821
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: MPG321 and short files

Fri Nov 06, 2020 3:01 pm

Do your TVs have an "auto volume" setting? To cut down noise on channel changes, many televisions blank out short sounds. If your sounds are suitably short, the TV may never play them audibly. I have that problem with my home monitor and speech synthesis: the first word is always lost.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

mmkw43
Posts: 699
Joined: Tue Dec 24, 2013 6:18 pm

Re: MPG321 and short files

Fri Nov 06, 2020 3:40 pm

yeah scruss, that seems like it may be it and probably is in many cases but this is weird.

first of all, if I use mpg123 rather than 321 -- there is slightly better performance playing the very same file on the very same tv.
if it was the tv alc, it wouldn't show a difference like that. one would think, anyway.

also if I play anything over 10 seconds or so, the tv will play it fine from the very beginning to the end.
i'm also having the audio chopped off when using a popular Jtech (amazon), audio extractor which is what I really need to use in the first place. as I said earlier in the post, I'm thinking of addind some silence to the beginning of the mp3 files to see what happens. I hear what you're saying though --
why some tv's dont work, others play it perfect. I wonder if it isn't poor design in "some" hdmi inputs.

not working in the jtech extractor is a real pisser. going to play with more this afternoon.

will not extract the short files audio BUT can hear it fine on TV ! ----

https://www.amazon.com/J-Tech-Digital-E ... s9dHJ1ZQ==

mmkw43
Posts: 699
Joined: Tue Dec 24, 2013 6:18 pm

Re: MPG321 and short files

Fri Nov 06, 2020 6:15 pm

I'm wondering also if there are any command line options with mpg123 that may make a difference? And other command line audio players to try?

And listen to this -- I installed Alsaplayer, played the short file and it does the complete opposite. Plays the beginning perfectly and chops off the end. ?

One of the words I use is "Warm line". Mpg123 plays a bit of "line" Alsaplayer plays "Warm".

Weird. There must be an explanation. Has to be "something" about short files with these players.


EDIT --
AND NOW, THIS JUST IN.

IF I GO TO FREETTS , CREATE AN MP3 FILE AND ADD 1 SECOND OF PAUSE AT THE START, MPG123 (AND 321) PLAYS IT PERFECTLY.

MAKES NO SENSE AS I CAN PLAY A BEATLES SONG JUST FINE YET WHERE IS THE PAUSE AT THE BEGINNING?? !



Here's what I think -- mpg123 and 321 have something in their code where it ignores files smaller than a certain size? maybe as a noise precaution? the files I created with the 1 second pause are 10kb or greater -- the ones I tried to play were smaller.
only thing I can think of.

User avatar
scruss
Posts: 3821
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: MPG321 and short files

Fri Nov 06, 2020 8:30 pm

mmkw43 wrote:
Fri Nov 06, 2020 3:40 pm
first of all, if I use mpg123 rather than 321 -- there is slightly better performance playing the very same file on the very same tv.
if it was the tv alc, it wouldn't show a difference like that. one would think, anyway.
ISTR mpg123 was the original, but someone didn't like the licence, so wrote mpg321
i'm also having the audio chopped off when using a popular Jtech (amazon), audio extractor
Has it got auto volume control?
Not all HDMI devices work with Raspberry Pis - this one may need special configuration to be recognized.
why some tv's dont work, others play it perfect. I wonder if it isn't poor design in "some" hdmi inputs.
It's most likely automatic volume. It cuts out the thump on channel changes and softens the obnoxious ramp up in volume when the ads start.

Adding silence won't help: the TV detects silence and is okay with that. TTS is particularly bad for lost utterances.

I think you'll have to configure every TV/monitor, and see if there are settings for the audio extractor that will work better. It's almost 100% not the software you are using to play sounds.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

User avatar
dickon
Posts: 1886
Joined: Sun Dec 09, 2012 3:54 pm
Location: Home, just outside Reading

Re: MPG321 and short files

Fri Nov 27, 2020 10:52 am

scruss wrote:
Fri Nov 06, 2020 8:30 pm
ISTR mpg123 was the original, but someone didn't like the licence, so wrote mpg321
mpg123 -- so named, AIUI, because it plays MPEG 1 layer 2 and layer 3 audio -- use(s?ed?) floating point maths to do all its work. mpg321 -- not 123, you see -- was an integer reimplementation fork. This mattered back in the days when most ARM chips were doing IEEE FP maths with emulation via the undefined instruction vector.

mmkw43: Please don't duplicate threads.
As it is apparently board policy to disallow any criticism of anything, as it appears to criticise something is to criticise all the users of that something, I will no longer be commenting in threads which are not directly relevant to my uses of the Pi.

User avatar
scruss
Posts: 3821
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: MPG321 and short files

Fri Nov 27, 2020 2:45 pm

WHY MPG321?

mpg123 is very popular because of its relative simplicity and its general facility. It is very good at what it does. At the time of mpg321 creation it was, however, under a non-free license: you can't incorporate its code into your own without getting special permission, and commercial entities also need special permission just to use it.

Being a Free Software advocate, I saw a deficiency in the dependency many people had on mpg123. Therefore, I created mpg321.
http://mpg321.sourceforge.net/about.html

mpg123 can now use fixed or floating point, and is under the LGPL. Seems like this was only yesterday, but it looks like it all went down in 1999. I think it uses the same integer routines as madplayer, as used in mpg321.

(back in the day I used Comprec/Shine as fast encoders on small ARM machines. The quality is terrible, but you can't beat the speed.)
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

Return to “Python”