I tried downloading the file and playing it using winsound to play it with the flag SND_MEMORY, but it only accepts str instead of the bytes object I got from urllib.request.urlopen. Using decode() needs a valid encoding, but I don't have one.
CLARIFICATION:downloading the file I mean as using urllib.request.urlopen to do it.

Use urlretrieve,something like this.

import winsound    
try:
    # Python2
    from urllib import urlretrieve
except ImportError:
    # Python3
    from urllib.request import urlretrieve

def play(sound):
    winsound.PlaySound(sound, winsound.SND_FILENAME)

# Download wave file and save to disk
url = "http://www.villagegeek.com/downloads/webwavs/adios.wav"
filename = url.strip().split('/')[-1]
urlretrieve(url, filename)
print("Sound saved as {}".format(filename))

# Play wave file
play(filename)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.