Set auto volume skill - problems on different devises


I am working on a auto set volume skill, that sets volume after how mch noice is in the room.
I got a prototype working on a picroft whith google voice kit. But when testing on mark_1 i ran into problems.

The skill reads mic thresh from os.path.join(get_ipc_directory(), “mic_level”) meaning /ramdisk/mycroft/ipc/mic_level. And then desides if volume should be set high or low.

But on picroft the file has this when no noice in room
Energy: cur=2 thresh=3.7810089716306976

on mark_1 the file has this when no noice in room
Energy: cur=551 thresh=747.0783252534047

So how to make the deside what is no noice and not?

I read the line in the file, and split it to get meter_thresh and then if it is low set volume low and high set volume high. But when thresh can be different on different devises I cant figure out how to make the code so i accounts for that.

 parts = line.split("=")
                meter_thresh = float(parts[-1])
                meter_cur = float(parts[-2].split(" ")[0])
                if meter_thresh > 5:
                    volume = 75
                if meter_thresh < 5:
                    volume = 35

Any good ideas are apriciated.

My skill can be found at GitHub here
Notise: the skill is working, but needs much more love and error handling as well as settings and voicecommands. But it Does auto set volume :slight_smile:


This is just a guess @andlo, but I suspect the volume level is a function of the microphone that is being used. This can be known in advance with the Mark 1, but because of the Plug n Play nature of the Picroft, it may be more difficult with the variety of microphones that can be used.

You may need to figure out a way to see if you can identify;

  • what the max and min volumes are for a microphone
  • some sort of averaging or levelling with the sampling

Great idea! Very excited to see where this goes :slight_smile:


I think the Energy-values are highly dependent a) on the device/microphone and b) the environmental noise level (I suspect that the sensitivity threshold is also re-adjusted by the noise level)

For example my Picroft with Google AIY kit shows:
Energy: cur=1 thresh=1.500000434700645

and my Mark-I:
Energy: cur=184 thresh=271.8215436639933


That is exactly what I see.

I am thinking the skill needs to have a calibrate funktion that saves high and low values.

Something like Hey Mycroft Set auto volume low noice and then he saves that value (adding 10%) and then make lots of noice and again Hey mcroft set auto volume high.
Same could be done for setting volumelevel so he knows what to do.

Alternative is let him run for a day or to and messure surroundings and then act acording to that. Then he learn what is high and what is low. And then he can ceep ajusting over time…That would make him think and act self :slight_smile:


I did some thinkong and some test today…

Messure Highand Lowest and calculating Lowlevel and highlevel from range between High and Low and lowlevel is low + 10% of range and Highlevel is 5 psc of range lower. And then setting volume high, middle or low acording to the levels.
That way Mr. Mycroft is adjusting and self learning. Now I just need to test how much (pct) lowlevel should be. Right now

Well it sounds strange and not understandible….
My code is

range = self.settings.get('HighNoice') - self.settings.get('LowNoice')
                lowlevel = self.settings.get('LowNoice') + (range/10)
                highlevel = self.settings.get('HighNoice') - (range/5) 

                if meter_thresh > highlevel:
                    volume = 75
                if meter_thresh < lowlevel:
                    volume = 35
                if meter_thresh < highlevel and meter_thresh > lowlevel:
                    volume = 60


Well - I got something working….

When initialize the miclevel is messured. And then a ringbuffer kiks ind messure every second for 120 steps. And that is used to get mic level (that removes strange sikes and the favt that when talking to microft he wouldnt change voicelevel because there were more noice when you talked)
Also higest and lowest avage of ringbuffer is stored and used to set lowlevel and highlevel values.

Due to the ringbuffer and storing higest and lowest messurements mycroft will learn how the surroundings is.

On the settings that user can set is Hig volume, normal volume and low volume. So mycroft knpws what volumelevel to set when he thinks there is silent, normal or high noice.

It seems to work - now i will let hin run for a day or to to se how he acts :slight_smile: