【问题标题】:the playsound module is giving this unexpected error in pythonplaysound 模块在 python 中给出了这个意外错误
【发布时间】:2022-09-30 18:52:02
【问题描述】:

我正在尝试在 python 中编写一个代码,让你玩音乐椅,为此我需要以这样一种方式编写代码,以便我可以启动计时器并同时播放音乐,所以我使用这个 playsound 模块,但它给了我这个意外的错误:

    Error 263 for command:
        open \"F:\\My_codes\\python\\Dbot\\dependencies\\songs\"        
    The specified device is not open or is not recognized by MCI.

    Error 305 for command:
        close \"F:\\My_codes\\python\\Dbot\\dependencies\\songs\"
    Cannot specify extra characters after a string enclosed in quotation marks.
Failed to close the file: \"F:\\My_codes\\python\\Dbot\\dependencies\\songs\"
Exception in thread Thread-1 (play_sound):
Traceback (most recent call last):
  File \"C:\\python310\\lib\\threading.py\", line 1009, in _bootstrap_inner
    self.run()
  File \"C:\\python310\\lib\\threading.py\", line 946, in run
    self._target(*self._args, **self._kwargs)
  File \"f:\\My_codes\\python\\musical_chair.py\", line 19, in play_sound
    playsound.playsound(song_path)
  File \"C:\\python310\\lib\\site-packages\\playsound.py\", line 72, in _playsoundWin
    winCommand(u\'open {}\'.format(sound))
  File \"C:\\python310\\lib\\site-packages\\playsound.py\", line 64, in winCommand
    raise PlaysoundException(exceptionMessage)
playsound.PlaysoundException: 
    Error 263 for command:
        open \"F:\\My_codes\\python\\Dbot\\dependencies\\songs\"
    The specified device is not open or is not recognized by MCI.

这是代码顺便说一句:

import time 
import playsound 
from threading import Thread
import random


def musical_chair(players):
    start_time = time.time()
    directory = \"F\"
    song_path = f\"{directory}:\\\\My_codes\\\\python\\\\Dbot\\\\dependencies\\\\songs\"
    

    seconds = [\'10\', \'11\', \'12\', \'13\', \'14\', \'15\', \'16\', \'17\', \'18\', \'19\', \'20\', \'21\', \'22\', \'23\', \'24\', \'25\', \'26\', \'27\', \'28\', \'29\', \'30\', \'31\', \'32\', \'33\', \'34\', \'35\', \'36\', \'37\', \'38\', \'39\', \'40\', \'41\', \'42\', \'43\', \'44\', \'45\', \'46\', \'47\', \'48\', \'49\', \'50\', \'51\', \'52\', \'53\', \'54\', \'55\', \'56\', \'57\', \'58\', \'59\', \'60\']

    time_played=\"\".join(random.sample(seconds,1))
    print(time_played)

    def play_sound(): 
        playsound.playsound(song_path)

    t=Thread(target=play_sound)
    t.daemon=True
    t.start()

    while (time.time()-start_time)<int(5):         
        # print(\"running....\")
        pass
musical_chair(2)

    标签: python timer playsound


    【解决方案1】:

    '''这样试试--------

    from playsound import playsound #go to online .mp3 to wav转换器

    playsound("C:\Users\ANURAG\Music\play.wav") '''

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-02
      • 2019-04-21
      • 2021-07-03
      • 2014-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多