简体   繁体   English

如何停止从playsound播放的声音

[英]How to stop the sound playing from playsound

i have made a python script which plays audio files, but when i am pressing Ctrl + C it is not stopping, the sound is continuously playing...我制作了一个播放音频文件的 python 脚本,但是当我按下 Ctrl + C 时,它并没有停止,声音一直在播放......

My Code:我的代码:

from playsound import playsound as splay
from os.path import isfile
import sys

def usage():
    print("\nSplay - Version[1]")
    print("Usage:\n\tsplay filename.mp3/wav")
    exit(0)

if len(sys.argv) < 2:
    print("filename argument missing !!!")
    usage()
    exit(1)

filenm = sys.argv[1]

if not isfile(filenm):
    print("filename invalid !!!")
    usage()
    exit(1)

splay(filenm)

so is there a way to stop this or a better way to play sound using python & i am on Debian based linux distro with python 3.9那么有没有办法停止这个或更好的方法来使用 python 播放声音 & 我在基于 Debian 的 linux 发行版与 Z653EEEB43947BBDD5

Thanks for answering in advance感谢您提前回答

This thread is about the same problem: stopping audio with playsound module (you'll find the module-specific solution in second answer from Artemis using the multiprocessing module.该线程与相同的问题有关: 使用 playsound 模块停止音频(您将在 Artemis 使用multiprocessing模块的第二个答案中找到特定于模块的解决方案。

Here is the code:这是代码:

import multiprocessing
from playsound import playsound

p = multiprocessing.Process(target = playsound, args = ('music.mp3',))
p.start()
wait = input('press ENTER to stop playback')
p.terminate()

The other answer recommend not using the playsound module, but switch to a different one.另一个答案建议不要使用playsound模块,而是切换到不同的模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM