Play audio several times on speaker

Hi all,
sorry for my poor English and this is my first topic.
I’m looking for a way to add actions to animation_data.nla_tracks some times corresponding to specific frames, in details I’m trying to simulate operator work on PC, each time the operator click on a key on the keyboard I want to play a sound on the speaker I added near to PC.
The speaker has a sound as sound.mp3
I execute some times the following code varying value of frame:

speaker = bpy.data.objects['speaker_operator']
context.scene.frame_current = frame
if speaker.animation_data is None:
    speaker.animation_data_create()
anim_data = speaker.animation_data
anim_data.use_nla = True
if len(anim_data.nla_tracks.values()) == 0:
    track = anim_data.nla_tracks.new()
else:
    track = anim_data.nla_tracks.values()[0]
action = bpy.data.actions.new(name='SOUND')
strip = track.strips.new("click",frame,action)

Some thing goes wrong, in NLA editor I see SOUND actions corresponding to frames but the speaker does not play audio. My doubt is about the action object, how could I get a correct action?

I am not sure about what you are trying to do in NLA, I have very little knowledge of that, but, Blender ships with the Aud sound library, used in VSE for example.

I have been working with this lately in an experimental system documented here: Clockworx Music Nodes - some issues to solve

In this I can have sound files played at specific times in the animation, or use the nodes to add sounds into VSE to play during the animation. You can make a Modal Operator to activate a sound when a key is pressed, this I know but have not looked at yet, part of my development will be to include MIDI input, that I have already done for animation Nodes using various Python libraries, see this: https://blenderartists.org/t/were-in-the-midi-audio-daw-real-time/1142160

So this may provide you a better way to go if nobody can answer your question directly. My new node system is still in its infancy, so it is not a released product yet.

Cheers, Clock.

Thanks a lot

Your experimental system is very interesting, I’ll try to get some ideas from it.

In order to to better explain my need:
I want to automate some tutorials about linux shell, e.g. use of VIM, GIT…
The automator is hosted at https://github.com/antoniochiurla/tutaut
I have built a bash framework go generate these tutorial, running the automator I produce the video record of virtual user’s screen and a detailed log of operations, in this log there are the timing of keyboard press and I want to play a short mp3 each time the virtual user press a key.
Then I’m writing Python script to import the videos shown in screen on PC on the scene, and log to animate the scene moving the camera from the PCs of virtual users.
Now I want to simulate the noise of clicking the keys on keyboard, then I’ve added speakers near to keyboards and added to speakers the mp3 audio. The problem is: how can I play the audio at specific frames, e.g.:
speaker1 at frames: 240, 300, 350, 380, 420 etc…
speaker2 at frames: 1230, 1280, 1310 etc…