![]() ![]() Os is a standard Python module that doesn’t need to be installed. ![]() Lastly, run the code and your audio will begin playing.Import playsound aysound(‘testaudio.mp3’) Next, enter the following piece of code:.First, enter the following in the Terminal:.Playing Sound, Audio, or MP3 Files in Python on Linux Using Playsound Then, the program will finish executing after 4 seconds as specified by the time.sleep() function. Import pygame import time () # initialize mixer module ('testaudio.mp3') () print("Audio will play for 4 seconds") time.sleep(4)įirst, the audio will start playing, and the result of the print function will be shown on the screen. Second, enter the following in your code editor:.Pygame is a game development module that is cross-platform and enables us to use Python for graphics and audio purposes. The program will finish executing right after as that is the time we specify in time.sleep(4). At the same time, the result of the print function is shown to indicate that the audio is 4 seconds long. When running the program, it should look something like this:Ī terminal window will appear and your audio should start playing. The time.sleep(4) function tells the program to delay execution for 4 seconds before we call the p.stop() function. Import vlc import time p = vlc.MediaPlayer(‘testaudio.mp3’) p.play() print("The audio will finish playing in 4 seconds") time.sleep(4) p.stop() In your code editor, enter the following:. ![]() Otherwise, the file will finish executing immediately without our audio being played. The time module enables us to determine how long we want the file to delay execution so we can hear our audio being played.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |