So I am interested with a python Module to play audio file, you can find it , it's pydub. So today I will show you how to play audio files (more than one).
Requirements:
1. Python.
2. IDE (optional) / Text editor.
Procedure:
1. Open Your IDE or if you don't have you can use text editor!
2. Let's import some module which we need!
import os
import glob
from pydub import AudioSegment
from pydub.playback import play
3. Let's go to our desired folder! we can use os.chdir("/our/desired/directory"), for my case I will type " os.chdir("/home/ahmad/Music/massiv") "
os.chdir("/home/ahmad/Music/massiv")
4. Make a variable , I use "Lagu" as variable, it's mean "song in English"!
lagu =
5. Let's give our variable a function, I use glob module for search audio files.
lagu=glob.glob("*.m4a")
6. And last step, the key is "Array Function"
for i in lagu:
s = AudioSegment.from_file(i, i.split(".")[-1])
play(s)
7. if we combine all part , it become like this:
import os
import glob
from pydub import AudioSegment
from pydub.playback import play
os.chdir("/home/ahmad/Music/massiv")
lagu=glob.glob("*.m4a")
for i in lagu:
s = AudioSegment.from_file(i, i.split(".")[-1])
play(s)
8. finally we can run our code, I use linux terminal, so I run the code by:
"python3 -i our_code.py"
here the image of our code:
Requirements:
1. Python.
2. IDE (optional) / Text editor.
Procedure:
1. Open Your IDE or if you don't have you can use text editor!
2. Let's import some module which we need!
import os
import glob
from pydub import AudioSegment
from pydub.playback import play
3. Let's go to our desired folder! we can use os.chdir("/our/desired/directory"), for my case I will type " os.chdir("/home/ahmad/Music/massiv") "
os.chdir("/home/ahmad/Music/massiv")
4. Make a variable , I use "Lagu" as variable, it's mean "song in English"!
lagu =
5. Let's give our variable a function, I use glob module for search audio files.
lagu=glob.glob("*.m4a")
6. And last step, the key is "Array Function"
for i in lagu:
s = AudioSegment.from_file(i, i.split(".")[-1])
play(s)
7. if we combine all part , it become like this:
import os
import glob
from pydub import AudioSegment
from pydub.playback import play
os.chdir("/home/ahmad/Music/massiv")
lagu=glob.glob("*.m4a")
for i in lagu:
s = AudioSegment.from_file(i, i.split(".")[-1])
play(s)
8. finally we can run our code, I use linux terminal, so I run the code by:
"python3 -i our_code.py"
here the image of our code:
thanks for visit and read this ugly blog...
