I wrote a little silly program to play a song whenever F12 is pressed, but when I'm not in the CMD itslef it doesn't realize when I press F12, and if I try to use it as .pyw it doesn't do anything at all. Here's the code:
from msvcrt import getch
import pyaudio
import wave
chunk = 1024
CHEEKI = r"my directory"
breeki = wave.open(CHEEKI, "rb")
p = pyaudio.PyAudio()
stream = p.open(format=p.get_format_from_width(breeki.getsampwidth()),
channels=breeki.getnchannels(),
rate=breeki.getframerate(),
output=True)
data = breeki.readframes(chunk)
while True:
key = ord(getch())
if key == 224:
while data != '':
stream.write(data)
data = breeki.readframes(chunk)
stream.stop_stream()
stream.close()
p.terminate()
Aucun commentaire:
Enregistrer un commentaire