From 9074acbb4f6e40638416f4561ab61fb187145243 Mon Sep 17 00:00:00 2001 From: dvs1 Date: Thu, 31 Oct 2024 16:02:35 +1000 Subject: Move the espeak stuff into it's own function, might help get it to behave. So far, got partial behaviour, seems to have stopped pausing rest of scripts text output until script end. --- aataaj.lua | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'aataaj.lua') diff --git a/aataaj.lua b/aataaj.lua index 16838ca..59e58f1 100755 --- a/aataaj.lua +++ b/aataaj.lua @@ -180,31 +180,39 @@ print('') io.flush() +local speak = function(card, subdevice, device, words, printIt, forkIt) + if printIt then print(words) end + if forkIt then + __('#!/bin/bash\necho "' .. words .. '" | ' .. speaker .. ' -d ' .. card .. subdevice):noErr():noOut():fork() + else + __('#!/bin/bash\necho "' .. words .. '" | ' .. speaker .. ' -d ' .. card .. subdevice):noErr():noOut():Do() + end +-- io.flush() +end + if 'start' == arg[1] then print('Your ' .. cnt .. ' audio devices are ') for k,C in pairs(Cards) do - print('' .. C.card - 1 .. ' : ' .. C.name) - __ ('ALSA_CARD=' .. C.card - 1 .. ' ' .. speaker .. ' "Your ' .. cnt .. ' audio devices are "'):log():noErr():noOut():fork() + for j,c in ipairs(C['playbackDevs']) do + speak(C.name, C['playbackDevs'][j], C.card - 1, 'Your ' .. cnt .. ' audio devices are - ', false, true) + end end -- TODO - should do a proper "wait for speakers to finish" here. Have fork(write a file), think that's what :wait(file) does. __'sleep 6':Do() - print('') - io.flush() for k,C in pairs(Cards) do - print('' .. C.card - 1 .. ' : ' .. C.name) - __('echo "' .. C.card - 1 .. ' : ' .. C.name .. '"') - __('ALSA_CARD=' .. C.card - 1 .. ' ' .. speaker .. ' "Device number ' .. C.card - 1 .. ' ' .. C.name .. '"'):log():noErr():noOut():Do() - io.flush() + for j,c in ipairs(C['playbackDevs']) do + speak(C.name, C['playbackDevs'][j], C.card - 1, 'Device number ' .. C.card - 1 .. ', ' .. C['playbackDevs'][j] .. ' : ' .. C.name, true, false) + end __'sleep 1':Do() end - print('') io.flush() + print('Please type the device number you heard best - ') for k,C in pairs(Cards) do - print('' .. C.card - 1 .. ' : ' .. C.name) - __('ALSA_CARD=' .. C.card - 1 .. ' ' .. speaker .. ' "Please type the device number you heard best."'):log():noErr():noOut():fork() + for j,c in ipairs(C['playbackDevs']) do + speak(C.name, C['playbackDevs'][j], C.card - 1, 'Please type the device number you heard best - ', false, true) + end end - io.write('Please type the device number you heard best - ') local choice = tonumber(io.read()) -- Lua has no way of just checking IF there is ANY input, so can't do "check if there was a keypress, continue if not". local ourCard = '' -- cgit v1.1