On this page

onMusic2RgbChange(callback: (data: MusicRgbCallbackData) => void, musicOption?: MusicRgbOption)

Requires:
@ray-js/panel-sdk≥1.7.0

Description

Start music rhythm monitoring and convert microphone audio to HSV color data in real time

Parameters

ParameterTypeRequiredDescription
callback(data: MusicRgbCallbackData) => voidYesAudio RGB change callback, receives music‑rhythm data such as hue/saturation/value
NoRhythm configuration (optional)

Return Value

Type: Promise<unknown>
Operation result Promise

Referenced Types

typeMusicRgbCallbackDataonMusic2RgbChange callback parameter type
PropertyTypeRequiredDescription
modenumberYesColor transition mode: 0 instant switch, 1 gradual transition
huenumberYesHue, range 0–360
saturationnumberYesSaturation, range 0–1000
valuenumberYesValue, range 0–1000
brightnumberYesBrightness, range 0–1000
temperaturenumberYesColor temperature, range 0–1000
dbnumberYesDecibel value, supported in v1.13.2+
indexnumberYesSensitivity index, supported in v1.13.2+
YesCustom property passthrough, supported in v1.13.2+

Valid Values

MusicRgbOption.mode
ValueDescriptionSince
0--
1--

Examples

Basic usage

import { kit } from '@ray-js/panel-sdk';
const { onMusic2RgbChange } = kit.music2rgb;

onMusic2RgbChange(({ hue, saturation, value }) => {
  publishDps({ colour_data: { hue, saturation, value } });
});

Custom color list

import { kit } from '@ray-js/panel-sdk';
const { onMusic2RgbChange } = kit.music2rgb;

onMusic2RgbChange(
  ({ hue, saturation, value }) => {
    publishDps({ colour_data: { hue, saturation, value } });
  },
  {
    mode: 1,
    colorList: [
      { hue: 0, saturation: 1000, value: 1000 },
      { hue: 120, saturation: 1000, value: 1000 },
      { hue: 240, saturation: 1000, value: 1000 },
    ],
    dBRange: [30, 70],
    throttle: 200,
  }
);

Notes

  • Question 1: How to determine the response status of the music rhythm?
  • Solution: You can cache the return values of the previous 5 times (approximate number, adjustable by yourself). If the 5 times are the same, it is considered that the music rhythm response status remains unchanged, so the status is changed to no response, otherwise it is considered that the music rhythm responds.