0

So I have a project I've been working on that mixes the Audio library Sounddevice and the input library Keyboard. By themselves I have been able to make things work, but when I mixed them I started running into trouble. Specifically if I take the keyboard hotkey command to try and trigger a sound effect it causes and EOF. Hotkeys being used to do other Keyboard commands work no matter what, but it seems to have trouble with mixing. I have been reading the docs for both but I cant find a clear cut system for overlapping the libraries. Any loops i have tried haven't seemed to work either, though many of them have been poorly written because I just don't know how to pull stuff like that from a seemingly unrelated segment. Here's what I have.

import keyboard 
import sounddevice as sd
import soundfile as sf
fileC = 'C:\\Users\\**\\AppData\\Local\\Programs\\Python\\Python38\\Project\\PianoC.wav'

keyboard.add_hotkey('esc', lambda: keyboard.wait)

keyboard.add_hotkey('n', lambda: keyboard.write(" Hello"))
keyboard.add_hotkey('j', lambda: keyboard.write(" Hi"))
keyboard.add_hotkey('i', lambda: keyboard.write(" Hey"))
#These three worked without problem of not being put in a loop

keyboard.add_hotkey('c', lambda: keyboard.write(data,fs = sf.read(fileC,dtype ='float32'))        
#This always gives an EFO
tdelaney
  • 73,364
  • 6
  • 83
  • 116

0 Answers0