#!/bin/bash

# Verify if rnnoise is already running, and only wait one second to try again, if it is not after 10 seconds go ahead
# for i in {1..10}; do
#     if pw-cli ls | grep -q effect_output.rnnoise; then
#         break
#     else
#         sleep 1
#     fi
# done

# Get the list of microphones that are not already linked to rnnoise
CommandOutput=$(pw-dump | jq -r '.[].info.props | select(.["media.class"] == "Audio/Source") | select(.["node.name"] != "effect_output.rnnoise") | .["node.name"] + "||||" + .["node.description"]')

declare -a name desc

while IFS= read -r line; do

    name+=(${line##*||||})
    desc+=(${line%%||||*})

done <<< $CommandOutput

echo "${name[1]}"



# Direct all microphones to rnnoise
# for mic in $micList; do
#     pw-link $mic effect_input.rnnoise
# done
