PyQT5 Q声音之间的声音延迟

2024-09-25 02:27:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用PyQt5制作一个数字钢琴软件,它的功能之一是能够自动弹奏音符。我已经在一个列表中注册了几个音符,并且正在尝试使用QSound来播放它们,但是当我这样做时,它们会同时播放。我如何才能在声音之间添加延迟?谢谢你的帮助

def playSheetMusic(self, Piano):
        sheetmusic = ["A5", "G4", "C4", "C4", "C4"]
        note1 = sheetmusic[0]
        file1 = "pianokeys/" + note1 +".wav"
        note2 = sheetmusic[1]
        file2 = "pianokeys/" + note2 +".wav"
        QSound.play(file1)
        QSound.play(file2)

Tags: play软件数字file1pyqt5file2音符wav
1条回答
网友
1楼 · 发布于 2024-09-25 02:27:54

您只需使用qWait()函数添加延迟,如下所示:

from PyQt4 import QtTest

def playSheetMusic(self, Piano):
        sheetmusic = ["A5", "G4", "C4", "C4", "C4"]
        note1 = sheetmusic[0]
        file1 = "pianokeys/" + note1 +".wav"
        note2 = sheetmusic[1]
        file2 = "pianokeys/" + note2 +".wav"
        QSound.play(file1)
        QtTest.QTest.qWait(1000)        # put however many milliseconds delay you want
        QSound.play(file2)

希望这有帮助:)

相关问题 更多 >