Control volume of mpg123












0














Good time of day! Currently developing something like "smart home" and I need to start different audio streams with different volume level. For example, I want to hear background music with 20% of original volume but in case if someone press door bell then I want to hear that bell ring with 100% volume. For my purposes currently, I'm using mpg123 with Python scripts. Python script with pexpect runs mpg123 with needed settings like



mpg123 -vC <filename>


Current approach sends 's' like pause immediately after the player starts. Then I'm sending needed count of '-' like decrease volume by 2 to the player and resume it. Huh... it works but an implementation is ugly, and there is some gap between the player start and volume decreasing. At least I hear few first "packets" before python script actually pauses player and decrease volume.



Is there any way to reduce the volume by some command?
Is there any way to start mpg123 paused? At least to eliminate that gap



Thanks!










share|improve this question














bumped to the homepage by Community 13 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Pulseaudio or ALSA? Under Pulseaudio, you can control the volume per application, and it remembers the last volume by name of application. Some tools like paplay have options to set application or stream name. With pacmd, and you can script volume changes etc. Under ALSA< it's going to be a lot more difficult.
    – dirkt
    Jul 6 '17 at 7:20










  • I can use pulse or ALSA but I will be glad to use some higher level tool like player and control volume in it, not in system mixer
    – user922871
    Jul 6 '17 at 7:37
















0














Good time of day! Currently developing something like "smart home" and I need to start different audio streams with different volume level. For example, I want to hear background music with 20% of original volume but in case if someone press door bell then I want to hear that bell ring with 100% volume. For my purposes currently, I'm using mpg123 with Python scripts. Python script with pexpect runs mpg123 with needed settings like



mpg123 -vC <filename>


Current approach sends 's' like pause immediately after the player starts. Then I'm sending needed count of '-' like decrease volume by 2 to the player and resume it. Huh... it works but an implementation is ugly, and there is some gap between the player start and volume decreasing. At least I hear few first "packets" before python script actually pauses player and decrease volume.



Is there any way to reduce the volume by some command?
Is there any way to start mpg123 paused? At least to eliminate that gap



Thanks!










share|improve this question














bumped to the homepage by Community 13 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Pulseaudio or ALSA? Under Pulseaudio, you can control the volume per application, and it remembers the last volume by name of application. Some tools like paplay have options to set application or stream name. With pacmd, and you can script volume changes etc. Under ALSA< it's going to be a lot more difficult.
    – dirkt
    Jul 6 '17 at 7:20










  • I can use pulse or ALSA but I will be glad to use some higher level tool like player and control volume in it, not in system mixer
    – user922871
    Jul 6 '17 at 7:37














0












0








0







Good time of day! Currently developing something like "smart home" and I need to start different audio streams with different volume level. For example, I want to hear background music with 20% of original volume but in case if someone press door bell then I want to hear that bell ring with 100% volume. For my purposes currently, I'm using mpg123 with Python scripts. Python script with pexpect runs mpg123 with needed settings like



mpg123 -vC <filename>


Current approach sends 's' like pause immediately after the player starts. Then I'm sending needed count of '-' like decrease volume by 2 to the player and resume it. Huh... it works but an implementation is ugly, and there is some gap between the player start and volume decreasing. At least I hear few first "packets" before python script actually pauses player and decrease volume.



Is there any way to reduce the volume by some command?
Is there any way to start mpg123 paused? At least to eliminate that gap



Thanks!










share|improve this question













Good time of day! Currently developing something like "smart home" and I need to start different audio streams with different volume level. For example, I want to hear background music with 20% of original volume but in case if someone press door bell then I want to hear that bell ring with 100% volume. For my purposes currently, I'm using mpg123 with Python scripts. Python script with pexpect runs mpg123 with needed settings like



mpg123 -vC <filename>


Current approach sends 's' like pause immediately after the player starts. Then I'm sending needed count of '-' like decrease volume by 2 to the player and resume it. Huh... it works but an implementation is ugly, and there is some gap between the player start and volume decreasing. At least I hear few first "packets" before python script actually pauses player and decrease volume.



Is there any way to reduce the volume by some command?
Is there any way to start mpg123 paused? At least to eliminate that gap



Thanks!







python audio






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jul 5 '17 at 22:02









user922871

62




62





bumped to the homepage by Community 13 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 13 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • Pulseaudio or ALSA? Under Pulseaudio, you can control the volume per application, and it remembers the last volume by name of application. Some tools like paplay have options to set application or stream name. With pacmd, and you can script volume changes etc. Under ALSA< it's going to be a lot more difficult.
    – dirkt
    Jul 6 '17 at 7:20










  • I can use pulse or ALSA but I will be glad to use some higher level tool like player and control volume in it, not in system mixer
    – user922871
    Jul 6 '17 at 7:37


















  • Pulseaudio or ALSA? Under Pulseaudio, you can control the volume per application, and it remembers the last volume by name of application. Some tools like paplay have options to set application or stream name. With pacmd, and you can script volume changes etc. Under ALSA< it's going to be a lot more difficult.
    – dirkt
    Jul 6 '17 at 7:20










  • I can use pulse or ALSA but I will be glad to use some higher level tool like player and control volume in it, not in system mixer
    – user922871
    Jul 6 '17 at 7:37
















Pulseaudio or ALSA? Under Pulseaudio, you can control the volume per application, and it remembers the last volume by name of application. Some tools like paplay have options to set application or stream name. With pacmd, and you can script volume changes etc. Under ALSA< it's going to be a lot more difficult.
– dirkt
Jul 6 '17 at 7:20




Pulseaudio or ALSA? Under Pulseaudio, you can control the volume per application, and it remembers the last volume by name of application. Some tools like paplay have options to set application or stream name. With pacmd, and you can script volume changes etc. Under ALSA< it's going to be a lot more difficult.
– dirkt
Jul 6 '17 at 7:20












I can use pulse or ALSA but I will be glad to use some higher level tool like player and control volume in it, not in system mixer
– user922871
Jul 6 '17 at 7:37




I can use pulse or ALSA but I will be glad to use some higher level tool like player and control volume in it, not in system mixer
– user922871
Jul 6 '17 at 7:37










1 Answer
1






active

oldest

votes


















0














Options for Pulseaudio:



1) Stream the output of mpg123 into paplay, for example with something like



mpg123 --stdout ... | paplay --rate=44100 --format=s16le --channels=2 --stream-name=Music --client-name=Musicplayer --volume=65536


You can either set the volume on the commandline as above, or set the volume once in pavucontrol by client-name, and the next time the same application starts it will remember the volume. So if you use different client names, say Musicplayer and Bellringer, you can pre-set the volume once and for all, without having it to change from Python.



2) Use some other program to play MP3 files that uses Pulseaudio and either can set the client name, or has a recognizable client name, or has a option to set the volume. E.g.



mplayer -volume=... ...


Then you have the same options as above.



3) Use pamcd or pactl to set the volume of the stream that's playing, e.g.



pacmd set-sink-input-volume 42 50%


You can use something similar to



pacmd list-sink-inputs | egrep '(index)|(name)'


to find the index numer for a given stream or client name. Or parse the complete output in Python.



4) Use the DBUS interface of Pulseaudio from Python. This will require some programming.



I wouldn't advise to use Python with pexpect to somehow change the volume through the UI, that looks like a horrible kludge, and isn't really "higher level".






share|improve this answer





















  • Thanks a lot! Your answer is really helpful! Do you know any other ways to interact with the player? It will be good for me to softly increase/decrease volume value. Thanks!
    – user922871
    Jul 6 '17 at 19:00










  • With mpg123? No, I don't know ways to interact with it, and I wouldn't try. You can change the volume smoothly via pacmd or DBus.
    – dirkt
    Jul 6 '17 at 21:13











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f375595%2fcontrol-volume-of-mpg123%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Options for Pulseaudio:



1) Stream the output of mpg123 into paplay, for example with something like



mpg123 --stdout ... | paplay --rate=44100 --format=s16le --channels=2 --stream-name=Music --client-name=Musicplayer --volume=65536


You can either set the volume on the commandline as above, or set the volume once in pavucontrol by client-name, and the next time the same application starts it will remember the volume. So if you use different client names, say Musicplayer and Bellringer, you can pre-set the volume once and for all, without having it to change from Python.



2) Use some other program to play MP3 files that uses Pulseaudio and either can set the client name, or has a recognizable client name, or has a option to set the volume. E.g.



mplayer -volume=... ...


Then you have the same options as above.



3) Use pamcd or pactl to set the volume of the stream that's playing, e.g.



pacmd set-sink-input-volume 42 50%


You can use something similar to



pacmd list-sink-inputs | egrep '(index)|(name)'


to find the index numer for a given stream or client name. Or parse the complete output in Python.



4) Use the DBUS interface of Pulseaudio from Python. This will require some programming.



I wouldn't advise to use Python with pexpect to somehow change the volume through the UI, that looks like a horrible kludge, and isn't really "higher level".






share|improve this answer





















  • Thanks a lot! Your answer is really helpful! Do you know any other ways to interact with the player? It will be good for me to softly increase/decrease volume value. Thanks!
    – user922871
    Jul 6 '17 at 19:00










  • With mpg123? No, I don't know ways to interact with it, and I wouldn't try. You can change the volume smoothly via pacmd or DBus.
    – dirkt
    Jul 6 '17 at 21:13
















0














Options for Pulseaudio:



1) Stream the output of mpg123 into paplay, for example with something like



mpg123 --stdout ... | paplay --rate=44100 --format=s16le --channels=2 --stream-name=Music --client-name=Musicplayer --volume=65536


You can either set the volume on the commandline as above, or set the volume once in pavucontrol by client-name, and the next time the same application starts it will remember the volume. So if you use different client names, say Musicplayer and Bellringer, you can pre-set the volume once and for all, without having it to change from Python.



2) Use some other program to play MP3 files that uses Pulseaudio and either can set the client name, or has a recognizable client name, or has a option to set the volume. E.g.



mplayer -volume=... ...


Then you have the same options as above.



3) Use pamcd or pactl to set the volume of the stream that's playing, e.g.



pacmd set-sink-input-volume 42 50%


You can use something similar to



pacmd list-sink-inputs | egrep '(index)|(name)'


to find the index numer for a given stream or client name. Or parse the complete output in Python.



4) Use the DBUS interface of Pulseaudio from Python. This will require some programming.



I wouldn't advise to use Python with pexpect to somehow change the volume through the UI, that looks like a horrible kludge, and isn't really "higher level".






share|improve this answer





















  • Thanks a lot! Your answer is really helpful! Do you know any other ways to interact with the player? It will be good for me to softly increase/decrease volume value. Thanks!
    – user922871
    Jul 6 '17 at 19:00










  • With mpg123? No, I don't know ways to interact with it, and I wouldn't try. You can change the volume smoothly via pacmd or DBus.
    – dirkt
    Jul 6 '17 at 21:13














0












0








0






Options for Pulseaudio:



1) Stream the output of mpg123 into paplay, for example with something like



mpg123 --stdout ... | paplay --rate=44100 --format=s16le --channels=2 --stream-name=Music --client-name=Musicplayer --volume=65536


You can either set the volume on the commandline as above, or set the volume once in pavucontrol by client-name, and the next time the same application starts it will remember the volume. So if you use different client names, say Musicplayer and Bellringer, you can pre-set the volume once and for all, without having it to change from Python.



2) Use some other program to play MP3 files that uses Pulseaudio and either can set the client name, or has a recognizable client name, or has a option to set the volume. E.g.



mplayer -volume=... ...


Then you have the same options as above.



3) Use pamcd or pactl to set the volume of the stream that's playing, e.g.



pacmd set-sink-input-volume 42 50%


You can use something similar to



pacmd list-sink-inputs | egrep '(index)|(name)'


to find the index numer for a given stream or client name. Or parse the complete output in Python.



4) Use the DBUS interface of Pulseaudio from Python. This will require some programming.



I wouldn't advise to use Python with pexpect to somehow change the volume through the UI, that looks like a horrible kludge, and isn't really "higher level".






share|improve this answer












Options for Pulseaudio:



1) Stream the output of mpg123 into paplay, for example with something like



mpg123 --stdout ... | paplay --rate=44100 --format=s16le --channels=2 --stream-name=Music --client-name=Musicplayer --volume=65536


You can either set the volume on the commandline as above, or set the volume once in pavucontrol by client-name, and the next time the same application starts it will remember the volume. So if you use different client names, say Musicplayer and Bellringer, you can pre-set the volume once and for all, without having it to change from Python.



2) Use some other program to play MP3 files that uses Pulseaudio and either can set the client name, or has a recognizable client name, or has a option to set the volume. E.g.



mplayer -volume=... ...


Then you have the same options as above.



3) Use pamcd or pactl to set the volume of the stream that's playing, e.g.



pacmd set-sink-input-volume 42 50%


You can use something similar to



pacmd list-sink-inputs | egrep '(index)|(name)'


to find the index numer for a given stream or client name. Or parse the complete output in Python.



4) Use the DBUS interface of Pulseaudio from Python. This will require some programming.



I wouldn't advise to use Python with pexpect to somehow change the volume through the UI, that looks like a horrible kludge, and isn't really "higher level".







share|improve this answer












share|improve this answer



share|improve this answer










answered Jul 6 '17 at 11:38









dirkt

16.7k21335




16.7k21335












  • Thanks a lot! Your answer is really helpful! Do you know any other ways to interact with the player? It will be good for me to softly increase/decrease volume value. Thanks!
    – user922871
    Jul 6 '17 at 19:00










  • With mpg123? No, I don't know ways to interact with it, and I wouldn't try. You can change the volume smoothly via pacmd or DBus.
    – dirkt
    Jul 6 '17 at 21:13


















  • Thanks a lot! Your answer is really helpful! Do you know any other ways to interact with the player? It will be good for me to softly increase/decrease volume value. Thanks!
    – user922871
    Jul 6 '17 at 19:00










  • With mpg123? No, I don't know ways to interact with it, and I wouldn't try. You can change the volume smoothly via pacmd or DBus.
    – dirkt
    Jul 6 '17 at 21:13
















Thanks a lot! Your answer is really helpful! Do you know any other ways to interact with the player? It will be good for me to softly increase/decrease volume value. Thanks!
– user922871
Jul 6 '17 at 19:00




Thanks a lot! Your answer is really helpful! Do you know any other ways to interact with the player? It will be good for me to softly increase/decrease volume value. Thanks!
– user922871
Jul 6 '17 at 19:00












With mpg123? No, I don't know ways to interact with it, and I wouldn't try. You can change the volume smoothly via pacmd or DBus.
– dirkt
Jul 6 '17 at 21:13




With mpg123? No, I don't know ways to interact with it, and I wouldn't try. You can change the volume smoothly via pacmd or DBus.
– dirkt
Jul 6 '17 at 21:13


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f375595%2fcontrol-volume-of-mpg123%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

サソリ

広島県道265号伴広島線

Accessing regular linux commands in Huawei's Dopra Linux