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
                self.log.info(volume)
                self.mixer.setvolume(volume)

Any good ideas are apriciated.

My skill can be found at GitHub here https://github.com/andlo/auto-set-volume-skill
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:

3 Likes

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:

1 Like

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
                self.mixer.setvolume(volume)
1 Like

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 home.mycroft.ai 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:

Hi @andlo! Setting the volume according to the background noise is a great idea especially when outdoors. Have you, or anybody else, figured out how to calibrate the microphone so that it doesn’t trigger with any click of the keyboard? Alternatively, is there an easy way to disable that ding sound when sound was detected but not the wakeword?

Thanks - It is one of my first skills, and I had to learn a lot python to make that :slight_smile:

I hassnt used Mycroft on laptop. But I would think Auto volume skill would think there were lots of noice as mic is close to keyboard and will register all the tapping.

The skill is working best on a standalone device like the Mark_1 and picroft.

If you want to disable the start listnig sound you could proberly set start_listening t none in the mycroft.conf

// File locations of sounds to play for system events
  "sounds": {
    "start_listening": "snd/start_listening.wav",
    "end_listening": "snd/end_listening.wav",
    "acknowledge": "snd/acknowledge.mp3"
  },

https://mycroft-ai.gitbook.io/docs/using-mycroft-ai/customizations/mycroft-conf

To do that you could use mycroft-config

mycroft-config:  Mycroft configuration manager
usage: mycroft-config [COMMAND] [params]

COMMANDs:
  edit (system|user)                  edit and validate config file
  reload                              instruct services to reload config
  show (default|remote|system|user)   display the specified setting file
  set <var>                           set the variable (under USER)
  get [var]                           display a particular variable
                                      or all if no 'var' specified
Note: Use jq format for specifying <var>

Examples:
  mycroft-config edit user
  sudo mycroft-config edit system
  mycroft-config show remote
  mycroft-config get
  mycroft-config get enclosure.platform
  mycroft-config set test.subvalue "foo"