0

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.

Edited by james.lu.75491856

2
Contributors
1
Reply
26
Views
4 Years
Discussion Span
Last Post by snippsat
2

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)

Edited by snippsat

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.