# Trying to change font weight based on volume of sound input

**URL:** <https://discourse.processing.org/t/trying-to-change-font-weight-based-on-volume-of-sound-input/39562>\
**Category:** Libraries\
**Created:** [November 3, 2022, 12:38am UTC](https://discourse.processing.org/t/trying-to-change-font-weight-based-on-volume-of-sound-input/39562 "2022-11-03T00:38:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![frogyolk](https://avatars.discourse-cdn.com/v4/letter/f/82dd89/32.png) [@frogyolk](https://discourse.processing.org/u/frogyolk)\
**Post date:** [November 3, 2022, 12:38am UTC](https://discourse.processing.org/t/trying-to-change-font-weight-based-on-volume-of-sound-input/39562/1 "2022-11-03T00:38:13Z")

</div>

sorry this is my first time posting, not sure if I’m doing this right. I’m trying to use the number of the sound input to select a font from an array but it won’t change the font even though it says the variable is changing.

Here’s my code:

var myRec = new p5.SpeechRec(‘en-US’, parseResult); // new P5.SpeechRec object  
myRec.continuous = true; // do continuous recognition  
myRec.interimResults = true; // allow partial recognition (faster, less accurate)

let mic;  
let v = 0;  
let font = [‘SpaceCowgirl-Thin.otf’,‘SpaceCowgirl-Light.otf’,‘SpaceCowgirl-Regular.otf’, ‘SpaceCowgirl-Medium.otf’, ‘SpaceCowgirl-Bold.otf’, ‘SpaceCowgirl-Black.otf’];  
let f=0;  
let t=‘SpaceCowgirl-Bold.otf’;

// function preload() {  
// myFont= loadFont(t);  
// }  
function setup() {  
let cnv = createCanvas(windowWidth, windowHeight);  
cnv.mousePressed(userStartAudio);  
myRec.onResult = parseResult; // now in the constructor  
myRec.start(); // start engine  
background(220);  
textSize(100);

fill(255,0,0);  
mic = new p5.AudioIn();  
mic.start();  
myFont= loadFont(t);  
}

function haw() {

// background(220);  
t= font[f];  
micLevel = mic.getLevel();  
v = micLevel\*10000;  
console.log(‘v =’,v);  
console.log(‘mic =’,micLevel);

if(2\>v\>0) f=0;  
else if(3\>v\>2) f=1;  
else if(4\>v\>3) f=2;  
else if(5\>v\>4) f=3;  
else if(6\>v\>5) f=4;  
else if(v\>6) f=5;

textFont(myFont);  
text(“HAW”,mouseX,mouseY);  
console.log('font ',myFont);  
console.log(‘f=’,f);  
console.log(‘t=’,t);  
}

function parseResult()  
{  
// recognition system will often append words into phrases.  
// so hack here is to only use the last word:  
var mostrecentword = myRec.resultString.split(’ ').pop();  
if(mostrecentword.indexOf(“yee”)!==-1) { haw(); }  
else if(mostrecentword.indexOf(“ye”)!==-1) { haw(); }  
else if(mostrecentword.indexOf(“you”)!==-1) { haw(); } else if(mostrecentword.indexOf(“yi”)!==-1) { haw();}  
else if(mostrecentword.indexOf(“yeet”)!==-1) { haw();}  
console.log(mostrecentword);  
}

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [November 3, 2022, 2:09pm UTC](https://discourse.processing.org/t/trying-to-change-font-weight-based-on-volume-of-sound-input/39562/2 "2022-11-03T14:09:46Z")

</div>

hi @frogyolk,

first please follow this instruction to [format-your-code](https://discourse.processing.org/faq#format-your-code)  
Second you are not changing the font in your code, only using the one from setup.

> [@frogyolk](#):
>
> let t=‘SpaceCowgirl-Bold.otf’;

> [@frogyolk](#):
>
> myFont= loadFont(t);

> [@frogyolk](#):
>
> textFont(myFont);

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![sableraph](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sableraph/32/251_2.png) [@sableraph](https://discourse.processing.org/u/sableraph)\
**Post date:** [November 3, 2022, 2:28pm UTC](https://discourse.processing.org/t/trying-to-change-font-weight-based-on-volume-of-sound-input/39562/3 "2022-11-03T14:28:20Z")

</div>

Hi @frogyolk. To format your code, edit your message, select your whole code, and press the `</>` button, like so:

![ezgif.com-gif-maker (1)](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/3/4/34521338de6902479873291389bf53a11d12237d.gif)
