from audiothread import *
th = AudioCommandThread()
th.start()
from audiothread import *
import queue
cmd_q = queue.Queue()
th = AudioCommandThread(cmd_q=cmd_q)
th.start()
cmd = TonePlayCommand(config=AudioConfig(fs=16000, ch=1), out_freq=440)
th.push(cmd)
def result_cb(detected_tones):
if len(detected_tones) == 0:
print("no detected tone.")
return
freq, amp = detected_tones[0]
if amp > 0:
print("detected: ", int(freq), " Hz", end="\r", flush=True)
cmd = ToneDetectCommand(config=AudioConfig(fs=16000, cb=result_cb), framemillis=100, nfft=4096)
th.push(cmd)
cmd.stop()
th.join()
Note that the cmd
will be "dirty" after calling cmd.stop()
and hence it will not be executed when it is pushed again, except for calling cmd.reset()
th.push(cmd)
# blablabla
cmd.stop()
# If you need to execute the same command again
cmd.reset()
th.push(cmd)