[英]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.