← Back to Blog

Embedded Alarm Sound Detection: Offline Alarm Recognition SDK with Graded ProtectionNEW

The Value of Alarm Detection: Scenarios and Workflow

A camera can see smoke, but it cannot hear a smoke alarm ringing while nobody is home. Alarm sound detection turns a passive recorder into an active guardian — but "an alarm" is not one sound. Smoke alarms, CO alarms and car alarms each carry a distinctive acoustic pattern, and recognizing which alarm matters far more than detecting "some alarm".

Scenario families: home safety cameras, elderly-care devices, in-vehicle and outdoor monitoring, and commercial security — all sharing the same engine.

Home alarm sensing scene
Detectors, cameras and push notifications working together

The Signatures of Three Alarm Types

Alarm signature patterns
Single-tone bursts, patterned pulses, and frequency sweeps

Below is a real alarm recording — waveform (top) and Mel spectrogram (bottom). The high-intensity sustained tone and regular harmonic stripes (the typical fingerprint of an alarm) are clearly visible:

Real alarm sample: waveform and spectrum
Real alarm sound sample: waveform (top) + Mel spectrogram (bottom)

Audio samples (real recordings — press play):

🔊 Alarm sound (real sample)

🔊 Another alarm recording

Smoke alarm — — a strong single-frequency pulse lasting several seconds; internationally standardized cadences (T3/T4) are common

CO alarm — — a regular pulse pattern (e.g., four pulses then a pause, the T4 pattern); the rhythm itself is the identity

Car alarm — — a sweeping "wail" or long tone with continuously gliding frequency — clearly different from fixed pulse patterns

These patterns are the key evidence: detection first verifies "this is an alarm-like pattern", then classifies which alarm it is.

How Recognition Works: Preprocessing → Features → Algorithms

The engine applies the standard pipeline (adaptive denoising, framing, time-frequency features) with pattern-centric decisions: single-frequency sustained tones, rhythmic pulse trains and frequency sweeps are three separable time-frequency trajectories. Relative-energy judgment keeps detection stable across quiet rooms and noisy kitchens. The main confusion sources — music, ringtones and speech — are handled through multi-class negative training.

Detection and notification flow
Pattern verification, classification, graded notification rules

Graded Notification: The Rules

1. Alarm event — pattern verification passed

2. Classification — smoke / CO / car / others

3. Graded notification — smoke or CO with nobody home means highest priority (push + phone call); car alarms are routine reminders

4. User handling — review, contact family, or mark as false alarm

Notification channels and grading rules are configurable per product and per household.

Elderly Care: When Hearing Is Protection

For seniors with reduced hearing or limited mobility, an alarm ringing unheard for minutes can escalate into an emergency. A care device that hears household alarms adds a layer cameras simply cannot cover.

Household sounds checklist
Smoke, CO, kettle whistles and door bells

Four categories matter most:

1. Smoke alarm — the most common trigger is an unattended stove; highest priority

2. CO alarm — invisible and odorless, higher risk when living alone; highest priority

3. Kettle / appliance whistles — catching a dry-boiling kettle early prevents escalation

4. Doorbell and phone rings — assistance when mobility is limited

Graded response flow
Detection, confirmation, notification and escalation

The response chain: alarm detection → class and confidence → scene check (is the senior home?) → immediate notification (push + phone call to children) → escalation when unanswered (neighbors, property management, emergency contacts) → event record. Escalation timing and contacts are fully configurable.

Elderly home scene
Living room scene with the child-side notification chain
Alarm timing and response data
When alarms happen, and how fast the response chain works (illustrative)

Alarm occurrences cluster around cooking times — exactly the windows where care should be most attentive. Response metrics: push delivery within seconds, minutes-level average review, configurable escalation window.

Positioning statement: this is a care-assistance tool that speeds up human response — it does not replace emergency services.

Accuracy and Performance

Alarm class and detection data
Class composition and detection rates across environments (illustrative)

In home scenes, smoke alarms dominate; detection stays above 93% even against kitchen noise and street backgrounds.

Item
Spec
Accuracy
96.0%
False alarm rate
<2%
Model size
0.2–1 MB (INT8)
Inference latency
Configurable to platform resources
Sample rate
16 kHz
Platforms
ARM Linux / MIPS / x86_64; SVP / Magik pre-adapted

Note: performance figures are based on internal test environments; actual results depend on hardware and deployment scenarios.

Platform and Hardware Requirements

From 100 MHz-class chips upward; the model shares the SoC with the device's main workload; suitable for battery-powered care devices.

C API and Embedded Integration

The alarm sound detection library exposes a concise streaming C API: the caller just keeps feeding 16 kHz mono PCM; framing, Mel preprocessing and model inference run internally, and frame-level probabilities are aggregated by the alarm strategy into event callbacks.

Full interface declaration (alarm_detect.h):

alarm_detect.hc
/**
 * alarm_detect.h — 警报声识别统一接口
 *
 * 封装 Mel 预处理 + 推理引擎 + 报警策略, 内部模型消费线程处理音频。
 * 与录音模块 (audio_capture.h) 相互独立: 调用者自行决定音频来源
 * (录音回调 / wav 文件 / 网络流), 通过 alarm_detect_feed 送入, 数据任意大小。
 *
 * 用法 (实时录音模式):
 *   alarm_detect_t *d = alarm_detect_create(mgk_path, NULL, NULL);
 *   alarm_detect_set_listener(d, on_frame, on_onset, on_offset, NULL);
 *   alarm_detect_start(d);                          // 启动内部模型消费线程
 *   audio_capture_start(rec, capture_cb, d);        // 录音回调里调 alarm_detect_feed
 *   ...
 *   alarm_detect_stop(d);                           // 排空缓冲, 停止线程
 *   alarm_detect_destroy(d);
 *
 * 用法 (wav 文件模式):
 *   alarm_detect_t *d = alarm_detect_create(mgk_path, NULL, NULL);
 *   alarm_detect_set_listener(d, on_frame, on_onset, on_offset, NULL);
 *   alarm_detect_start(d);
 *   循环读文件: alarm_detect_feed(d, pcm, n);       // 任意数据大小
 *   alarm_detect_stop(d);
 *   alarm_detect_destroy(d);
 */

#ifndef ALARM_DETECT_H
#define ALARM_DETECT_H

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

/* 识别事件 (报警策略输出, 用于事件结束回调) */
typedef struct {
    float start_time;       /* 事件开始时间 (秒) */
    float end_time;         /* 事件结束时间 (秒) */
    float confidence;       /* 事件置信度 */
    float max_confidence;   /* 事件内最大帧置信度 */
    int   frame_count;      /* 事件持续帧数 */
} alarm_detect_event_t;

/* 帧级回调: 每帧识别结果 (模型线程内执行) */
typedef void (*alarm_detect_frame_cb_t)(float alarm_prob, float timestamp,
                                        void *user_data);

/* 事件开始回调: 策略判定警报事件开始, 只有开始时间 */
typedef void (*alarm_detect_onset_cb_t)(float start_time, void *user_data);

/* 事件结束回调: 策略判定警报事件结束 (或停止识别时未结束的事件), 完整事件信息 */
typedef void (*alarm_detect_offset_cb_t)(const alarm_detect_event_t *event,
                                         void *user_data);

typedef struct alarm_detect_s alarm_detect_t;

/* 创建/销毁; alarm_name/alarm_params 可传 NULL (用默认策略及参数) */
alarm_detect_t *alarm_detect_create(const char *mgk_path,      /* 模型文件路径 (必填) */
                                    const char *alarm_name,    /* 报警策略名, NULL=默认 */
                                    const char *alarm_params); /* 策略参数 key=val,key=val, NULL=默认 */
void alarm_detect_destroy(alarm_detect_t *det);

/* 设置事件回调 (create 后调用, 也可在运行中调整); 不需要的回调传 NULL */
void alarm_detect_set_listener(alarm_detect_t *det,
                               alarm_detect_frame_cb_t  on_frame,
                               alarm_detect_onset_cb_t  on_onset,
                               alarm_detect_offset_cb_t on_offset,
                               void *user_data);

/* 启动/停止识别: 启动内部模型消费线程 / 排空缓冲后停止线程 */
int  alarm_detect_start(alarm_detect_t *det);
void alarm_detect_stop(alarm_detect_t *det);
int  alarm_detect_is_running(alarm_detect_t *det);

/* 设置事件识别策略 (可在运行中调整) */
int alarm_detect_set_alarm(alarm_detect_t *det, const char *alarm_name,
                           const char *alarm_params);

/* 送入 PCM 数据 (16bit 单声道 16kHz), 线程安全, 任意数据大小 */
int alarm_detect_feed(alarm_detect_t *det, const int16_t *pcm, int num_samples);

#ifdef __cplusplus
}
#endif

#endif /* ALARM_DETECT_H */

A minimal WAV-inference demo (excerpt; the full file ships at src/alarmDetect/c/alarm_demo.c):

alarm_demo.cc
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "alarm_detect.h"

#define DEFAULT_MGK  "alarm_detect_v7.mgk"  /* 模型文件 */
#define DEFAULT_WAV  "test_alarm.wav"       /* 16kHz 单声道 16bit PCM */
#define FEED_CHUNK   16000                  /* 每次送入 1 秒音频 */

/* 帧级回调: 每帧输出警报声概率 (约 1 秒一帧) */
static void on_frame(float alarm_prob, float timestamp, void *user_data)
{
    (void)user_data;
    printf("%8.2fs  alarm=%.4f\n", timestamp, alarm_prob);
}

/* 事件开始回调: 策略判定警报事件开始 */
static void on_onset(float start_time, void *user_data)
{
    (void)user_data;
    printf("[EVENT] alarm start at %.2fs\n", start_time);
}

/* 事件结束回调: 应用层可据此做后续统计或分级响应 */
static void on_offset(const alarm_detect_event_t *ev, void *user_data)
{
    (void)user_data;
    printf("[EVENT] alarm end at %.2fs (dur=%.2fs, conf=%.3f, frames=%d)\n",
           ev->end_time, ev->end_time - ev->start_time,
           ev->confidence, ev->frame_count);
}

static int read_wav_pcm(const char *path, int16_t **pcm, int *n, int *sr);  /* 完整实现见源文件 */

int main(void)
{
    alarm_detect_t *det;
    int16_t *pcm = NULL;
    int num_samples = 0, sample_rate = 0;
    int pos;

    if (read_wav_pcm(DEFAULT_WAV, &pcm, &num_samples, &sample_rate) != 0)
        return 1;

    /* 1. 创建识别器: 模型文件 + 默认报警策略 (NULL) */
    det = alarm_detect_create(DEFAULT_MGK, NULL, NULL);
    if (!det) return 1;

    /* 2. 注册回调 (均为可选) */
    alarm_detect_set_listener(det, on_frame, on_onset, on_offset, NULL);

    /* 3. 启动内部模型消费线程 */
    alarm_detect_start(det);

    /* 4. 分块送入 PCM; 实时录音时改在录音回调里 feed */
    for (pos = 0; pos < num_samples; pos += FEED_CHUNK) {
        int n = num_samples - pos;
        if (n > FEED_CHUNK) n = FEED_CHUNK;
        alarm_detect_feed(det, pcm + pos, n);
    }

    /* 5. 停止并销毁 */
    alarm_detect_stop(det);
    alarm_detect_destroy(det);
    free(pcm);
    return 0;
}

Build and run:

buildbash
$(CC) alarm_demo.c -I. -L. -lalarmdetect -lpthread -lm -o alarm_demo
./alarm_demo

Conclusion

Understanding alarms means understanding which alarm — and what it should trigger. An online trial with full technical support is available.