[英]How to play sound in Python WITHOUT interrupting music/other sounds from playing
[英]Is it possible in Python to play sound/music from website without open the browser?
我用 Selenium 找到了一些解决方案,但是 Selenium 打开浏览器播放选定的音乐,所以这对我来说不是完美的方式。
是否可以在不打开浏览器的情况下从网站播放音乐?
from requests import get
try:
from playsound import playsound
except:
from os import system
system('pip install playsound')
x = get(music_link).content
file = open('music.mp3','wb')
file.write(x)
file.close()
playsound('music.mp3')
您可能正在寻找 lib playsound
。
import os
import requests
import playsound
url = 'YOUR_URL_HERE'
downloaded_file_location = '/tmp/audiofile.wav'
# Downloading the audio file
r = requests.get(url)
with open(downloaded_file_location, 'wb') as f:
f.write(r.content)
# Playing the audio file
playsound.playsound(downloaded_file_location, True)
# Removing the audio file
os.remove(downloaded_file_location)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.