Skip to main content

SoundLevel

caution

This service is rc and may change in the future.

A sound level detector sensor, gives a relative indication of the sound level.

import { SoundLevel } from "@devicescript/core"

const soundLevel = new SoundLevel()

Registers

reading

The sound level detected by the microphone

  • type: Register<number> (packing format u0.16)

  • read only

import { SoundLevel } from "@devicescript/core"

const soundLevel = new SoundLevel()
// ...
const value = await soundLevel.reading.read()
  • track incoming values
import { SoundLevel } from "@devicescript/core"

const soundLevel = new SoundLevel()
// ...
soundLevel.reading.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.

enabled

Turn on or off the microphone.

  • type: Register<boolean> (packing format u8)

  • read and write

import { SoundLevel } from "@devicescript/core"

const soundLevel = new SoundLevel()
// ...
const value = await soundLevel.enabled.read()
await soundLevel.enabled.write(value)
  • track incoming values
import { SoundLevel } from "@devicescript/core"

const soundLevel = new SoundLevel()
// ...
soundLevel.enabled.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.

activeThreshold

Set level at which the loud event is generated.

  • type: Register<number> (packing format u0.16)

  • read and write

import { SoundLevel } from "@devicescript/core"

const soundLevel = new SoundLevel()
// ...
const value = await soundLevel.activeThreshold.read()
await soundLevel.activeThreshold.write(value)
  • track incoming values
import { SoundLevel } from "@devicescript/core"

const soundLevel = new SoundLevel()
// ...
soundLevel.activeThreshold.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.

inactiveThreshold

Set level at which the quiet event is generated.

  • type: Register<number> (packing format u0.16)

  • read and write

import { SoundLevel } from "@devicescript/core"

const soundLevel = new SoundLevel()
// ...
const value = await soundLevel.inactiveThreshold.read()
await soundLevel.inactiveThreshold.write(value)
  • track incoming values
import { SoundLevel } from "@devicescript/core"

const soundLevel = new SoundLevel()
// ...
soundLevel.inactiveThreshold.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.

Events

loud

Generated when a loud sound is detected.

soundLevel.loud.subscribe(() => {

})

quiet

Generated low level of sound is detected.

soundLevel.quiet.subscribe(() => {

})