Python 3 Script to Build Mini Audio Player to Play Audio Files in Terminal Using audioplayer Library
271 views
Jun 3, 2025
Get the full source code of application here: https://gist.github.com/gauti123456/884ff2dc8b0d97aab80b52606ffab222
View Video Transcript
0:00
uh hello guys welcome to this video So
0:02
in this video I will show you a Python
0:05
package which allows you to play audio
0:07
files directly in the
0:09
terminal So there is a package here If
0:12
you go to
0:13
the website of Python where you can
0:17
install third party packages just search
0:19
for this package audio player and this
0:22
is actually a crossplatform Python
0:24
module which allows you to play sounds
0:28
files directly in the terminal The
0:31
command is simple Simply install this
0:33
package by executing this command I've
0:36
already installed it So I basically have
0:39
the script here and I will play this
0:41
file here which is
0:43
audio.mpp3 So if I run this Python
0:46
script
0:48
here just wait let me run this script
0:52
here Python app
1:04
py So in this way you can see that the
1:07
audio was playing here You can even
1:08
control the volume as well So volume was
1:11
set to 10% And just press the Q keyword
1:15
to squit the
1:18
application So this is actually the
1:20
module Here you can control the audio
1:23
Let's suppose I change this audio to 80
1:25
So now if you see the volume will be
1:28
increased
1:36
So this is essentially this package here
1:38
Let me show you how to use
1:40
it step by
1:43
step So the full script is given in the
1:46
description of this video So first of
1:49
all you import the time module which is
1:51
a built-in module and also the threading
1:53
module which is a built-in And then we
1:56
import this third party package audio
1:58
player From this we import this audio
2:01
player class And then we also need to
2:04
import the keyboard module which will
2:06
actually
2:07
bind a shortcut key so that when you
2:10
press the key Q keyword the application
2:13
will close For this you just need to
2:16
install this third party module pip
2:18
install keyboard Also install this and
2:21
then we will initialize the audio
2:23
player like this And here you specify
2:26
the path of the audio file So my file is
2:31
output.mpp3 So simply I will provide the
2:34
audio file and then you can actually
2:36
access the details print out the name of
2:40
the file the full file name as well
2:42
alongside with the extension Then you
2:45
can simply control the volume level by
2:48
this property player volume
2:52
Let me set it to 20% And then
2:58
uh that's all that thing I is there Then
3:02
to play the audio we have the play
3:04
button play function And similarly if
3:07
you want to pause it if you want to stop
3:10
it all these functions are
3:13
available And now you can even set a
3:15
keyboard shortcut so that when you press
3:19
the Q
3:20
keyboard Q key on the keyboard the
3:22
application will
3:24
close For this I will just write a
3:27
custom function monitor key press So
3:31
when you press the Q keyboard the
3:33
application will close So here you see
3:35
that we are stopping the player Player
3:38
dots stop whenever user press the Q
3:40
keyword
3:42
So now we simply need to call
3:46
this function that we define right here
3:49
So with the help of threading module
3:52
threading dot thread target is monitor
3:54
key press and then we start this
4:01
thread and then we actually join
4:05
this So close the player after stopping
4:09
So we need to close the player after we
4:11
stop it So player dot close So this is
4:16
the overall script here And if I try to
4:18
execute this you will see that
4:32
uh so in this way you can play audio
4:36
files directly inside the terminal
4:38
inside Python using this package Thank
4:41
you very much for watching this video
4:43
and also check out my website
4:44
freemediatools.com
4:46
uh which contains thousands of tools
#Audio Equipment
#Consumer Electronics
#Intelligent Personal Assistants
#Multimedia Software
#Music & Audio
#Music Equipment & Technology
#Podcasts
#Software