How to play sound in Python WITHOUT interrupting music/other sounds from playing

Active3 hr before
Viewed126 times

5 Answers


import winsound

winsound.PlaySound('sound.wav', winsound.SND_FILENAME)
load more v

I am trying to get the audio to play in the background but unfortunately the mp3 file plays first before the function continues.,I am just writing a small python game for fun and I have a function that does the beginning narrative.,Also, is there any way of controlling the volume of the play sound module?, How do play audio playsound in background of...

How do I get it to run in the background?

import playsound

def displayIntro():
   playsound.playsound('storm.mp3', True)
print_slow('The year is 1845, you have just arrived home...')
load more v

winsound — Sound-playing interface for Windows,The sound parameter to PlaySound() is a memory image of a WAV file, as a bytes-like object.,The sound parameter is the name of a WAV file. Do not use with SND_ALIAS.,Play the SystemExclamation sound.

import winsound
# Play Windows exit sound.
winsound.PlaySound("SystemExit", winsound.SND_ALIAS)

# Probably play Windows
default sound,
if any is registered(because # "*"
      probably isn 't the registered name of any sound).
      winsound.PlaySound("*", winsound.SND_ALIAS)

how do i stop the audio playing through playaudio module in python code I have played music= playsound.playsound("name_of-file") but I cant stop that music. how can I stop it ,playsound.playsound("name_of_file"),Personally, I like to use pyaudio. The following code is adapted from the example here. The code plays audio and has the space bar set as a pause/play button.,Playsound is a single function module that plays sounds, and nothing else. It would seem that means it does not stop playing sounds either. From their own documentation:

You can use the multiprocessing module to play the sound as a background process, then terminate it anytime you want:

import multiprocessing
from playsound
import playsound

p = multiprocessing.Process(target = playsound, args = ("file.mp3", ))
input("press ENTER to stop playback")
load more v

Use the My.Computer.Audio.Stop method to stop the application's currently playing background or looping sound.,The following example stops a sound that is playing in the background.,In general, when an application plays a looping sound, it should eventually stop the sound.,In general, when an application plays a looping sound, it should stop the sound at some point.

In the following example, the My.Computer.Audio.Play method plays a sound. When AudioPlayMode.WaitToComplete is specified, My.Computer.Audio.Play waits until the sound completes before calling code continues. When using this example, you should ensure that the file name refers to a .wav sound file that is on your computer

Sub PlayBackgroundSoundFile()
End Sub
load more v

Other "without-python" queries related to "How to play sound in Python WITHOUT interrupting music/other sounds from playing"