Help With Volume Reader Python Code

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


for i in range(int(10*44100/1024)): #go for a few seconds
    data = np.fromstring(,dtype=np.int16)
    print("%04d %05d %s"%(i,peak,bars))


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!

You currently won't be able to stream live data to the BTT Touch Bar like this. BTT currently only allows to execute a script and then display the return value, but not a continuous stream. (Would be an interesting feature, but not sure if that's feasible - I'll have a look)

Currently the only option would be to write a custom BTT TOuch Bar plugin in native Swift or Objective-C or to constantly call the Apple Script methods that allow setting new text on a button / widget in BTT.

Well, looks like it's time to dive into swift. Thanks for the response Andreas!