如何解决当我将Pydub分配给变量时,它会立即播放,但是我不确定它在哪里播放音频文件
我是编码的新手,我正在尝试为我的石头,剪刀纸项目添加声音。该代码可以运行并完美运行,除了在调用音频之前播放音频的部分。
from random import randint
from pydub import AudioSegment
from pydub.playback import play
import urllib
import urllib; from urllib.request import urlopen
print("Will commence to download audio files")
dio = "Muda.mp3"
urllib.request.urlretrieve("https://media1.vocaroo.com/mp3/1hZpQIDaa49x",dio)
ab = AudioSegment.from_file(dio)
t = ['rock','paper','scissor']
computer = t[randint(0,2)]
player = False
while player == False:
win = ["LETS GOOOOO","Imagine losing to me","Well,its just your unlucky day",play(ab),'Saitama once said "Human beings are strong because we have the ability to change ourselves."']
lose = ["Your pretty lucky,arent you","You cheated,didn't you","I just let you win","That was fair and square","There's the Emote","F"]
那是重要的部分,但是完整的代码是
from random import randint
from pydub import AudioSegment
from pydub.playback import play
import urllib
import urllib; from urllib.request import urlopen
print("Will commence to download audio files")
dio = "Muda.mp3"
urllib.request.urlretrieve("https://media1.vocaroo.com/mp3/1hZpQIDaa49x","F"]
a = win[randint(0,4)]
b = lose[randint(0,5)]
player = str(input("Rock,Paper,Scissors?:")).lower()
if player == computer:
print(player,"vs",computer)
print("Tie")
elif player == "rock":
if computer == "paper":
print(player,computer)
print(a)
else:
print(player,computer)
print(b)
elif player == "paper":
if computer == "scissor":
print(player,computer)
print(b)
elif player == "scissors":
if computer == "rock":
print(player,computer)
print(a)
else:
print("Thats not a valid response")
player = False
computer = t[randint(0,2)]
a = win[randint(0,5)]
这里唯一的主要问题是在randint随机选择音频之前播放音频
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。