如何在python脚本中运行多个音频文件

如何在python脚本中运行多个音频文件,python,windows-10,Python,Windows 10,我已经用python创建了一个脚本,我想运行多个音频(.wav)文件,4。有重复的语句被编写,例如os.system,time.sleep多次出现,有没有一种方法可以通过只编写一次来多次运行迭代 import os import time command = "cmd" print (" Starting iteration") print ("Clearing device logs and will start to collect New logs") os.system (" adb

我已经用python创建了一个脚本,我想运行多个音频(
.wav
)文件,4。有重复的语句被编写,例如
os.system
time.sleep
多次出现,有没有一种方法可以通过只编写一次来多次运行迭代

import os
import time

command = "cmd"

print (" Starting iteration")
print ("Clearing device logs and will start to collect New logs")
os.system (" adb logcat -c")
time.sleep(3)

os.system (r'start C:\Alexa\whatshould.wav')
time.sleep(10)

print ("Capturing logs")
os.system (" adb logcat -d -v threadtime >> what_should_i_wear_today.txt")
time.sleep(3)

os.system (r'start C:\Alexa\wakeword.wav')
time.sleep(4)

print ("Capturing logs")
os.system (" adb logcat -d -v threadtime >> wakeword.txt")
time.sleep(3)

os.system (r'start C:\Alexa\photo.wav')
time.sleep(10)

print ("Capturing logs")
os.system (" adb logcat -d -v threadtime >> photo_capture.txt")
time.sleep(3)

os.system (r'start C:\Alexa\video.wav')
time.sleep(10)

print ("Capturing logs")
os.system (" adb logcat -d -v threadtime >> Video_capture.txt")
time.sleep(3)

我在windows中创建了它,我可以在mac等其他平台上使用该脚本吗?

假设您想运行目录中的所有曲目(
C:/Alexa
,在您的情况下),您可以使用
os.listdir()
函数返回该目录中所有文件的列表

import os
import time

command = "cmd"

print (" Starting iteration")
print ("Clearing device logs and will start to collect New logs")
os.system (" adb logcat -c")
time.sleep(3)


path = 'C:/Alexa/'
song_list = os.listdir(path)
song_list.sort()


for song in song_list:
    time.sleep(10)
    os.system (f'start {os.path.join(path, song)}')
    time.sleep(3)
    print ("Capturing logs")
    os.system (" adb logcat -d -v threadtime >> what_should_i_wear_today.txt")

是的,有办法。现在是你学习如何使用的时候了。这个命令可以播放所有的音频文件,有没有办法在所有音频文件之间留出15秒的时间间隔?@RoshanRaja据我所知,
time.sleep(10)
每次迭代应产生10秒的延迟。下一时刻播放的音频文件很少,10秒后播放的音频文件也很少。它随机选择音频文件。有没有办法让它按顺序选择?非常感谢你的帮助