Hey all, was looking for a little guidance to get my code working with the touch bar. This is a starting point for a project I've been messing around with and plan to grow it in the future.
I got this python code working: it's essentially a volume reader. It takes in the audio from the microphone and outputs a line of code that represents how loud the audio was.
import pyaudio import numpy as np CHUNK = 2**11 RATE = 44100 p=pyaudio.PyAudio() stream=p.open(format=pyaudio.paInt16,channels=1,rate=RATE,input=True, frames_per_buffer=CHUNK) for i in range(int(10*44100/1024)): #go for a few seconds data = np.fromstring(stream.read(CHUNK),dtype=np.int16) peak=np.average(np.abs(data))*2 bars="#"*int(50*peak/2**16) print("%04d %05d %s"%(i,peak,bars)) stream.stop_stream() stream.close() p.terminate()
Right now, it will output to terminal like this (this is me clapping):
What I'm having trouble with is getting this code to appear on the touch bar with BTT. Currently in BTT when I run the script, it outputs in the menu bar when I set it up like this:
However it does not print out every line individually. Rather it waits until the end and prints all the lines together. It also does not output anything to the touch bar, just within the "run script now" section in BTT.
I imagine this is an issue with me not converting the info being printed out into something that BTT can read and output.
Thank you for the help!