I wrote a script which plays audio when you press any key (that's a letter), but I'm not getting any audio, the script itself actualy works but I don't hear anything
import os
import keyboard, string, random
import pygame as pg
letter = string.ascii_letters
digit = string.digits
pg.init()
pg.mixer.init()
ks1 = "C:\\keypress\\key-press-1.mp3"
ks2 = "C:\\keypress\\key-press-2.mp3"
ks3 = "C:\\keypress\\key-press-3.mp3"
ks4 = "C:\\keypress\\key-press-4.mp3"
keyList = [ks1, ks2, ks3, ks4]
def typing(keySound):
if letter.find(keyboard.read_key())>-1:
pg.mixer.music.load(keySound)
pg.mixer.music.play()
def main():
while True:
keySound = random.choice(keyList)
print(keySound)
typing(keySound)
main()
Any help is appreciated!