Skip to content

feat: add STT latency and RTF tracking metrics - #9894

Open
buyun14 wants to merge 1 commit into
AstrBotDevs:masterfrom
buyun14:feat/stt-latency-tracking
Open

feat: add STT latency and RTF tracking metrics#9894
buyun14 wants to merge 1 commit into
AstrBotDevs:masterfrom
buyun14:feat/stt-latency-tracking

Conversation

@buyun14

@buyun14 buyun14 commented Sep 1, 2026

Copy link
Copy Markdown

Motivation / 动机

Add timing and real-time factor (RTF) metrics to speech-to-text (STT) calls so users can observe STT latency directly in the Live Mode dashboard. Currently the dashboard shows TTS/chat latency but no STT latency, and there is no per-call timing/RTF observability in the pipeline.

Modifications / 改动点

  • astrbot/core/pipeline/preprocess_stage/stage.py: in _stt_record, probe audio duration via get_media_duration, measure the STT call duration, log provider/model/duration/RTF, and record into event.trace for observability.

  • astrbot/dashboard/services/live_chat_service.py: measure web chat STT duration and emit stt_total_time / stt_audio_duration / stt_rtf metrics over the live chat websocket.

  • dashboard/src/components/chat/LiveMode.vue: render the new STT latency metrics (total latency, audio duration, RTF).

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

Ruff check and format check pass on the modified files. (Dashboard screenshots to be provided once verified.)


Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了"验证步骤"和"运行截图"

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Add STT timing and real-time factor observability across the pipeline and Live Mode dashboard.

New Features:

  • Expose STT latency, source audio duration, and real-time factor metrics in Live Mode.
  • Record per-call STT timing, provider, model, status, and RTF data in event traces.

Enhancements:

  • Add graceful handling when audio duration cannot be determined while preserving STT processing.

Track speech-to-text call timing and real-time factor (RTF) in both the pipeline preprocess stage and the web chat live chat service, and surface the metrics in the Live Mode dashboard.

- preprocess_stage: probe audio duration via get_media_duration, measure STT duration, log provider/model/duration/RTF, and record into event.trace for observability.
- live_chat_service: emit stt_total_time / stt_audio_duration / stt_rtf over the live chat websocket.
- LiveMode.vue: render the new STT latency metrics.
Copilot AI lite review requested due to automatic review settings September 1, 2026 08:24

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds STT observability (latency, audio duration, and real-time factor/RTF) to AstrBot’s pipeline tracing and Live Mode dashboard so users can see STT performance alongside existing LLM/TTS metrics.

Changes:

  • Record per-call STT timing, audio duration, RTF, provider/model, and status into event.trace.
  • Emit STT timing/RTF metrics over the Live Mode websocket for web chat.
  • Render the new STT metrics in the Live Mode UI.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
dashboard/src/components/chat/LiveMode.vue Displays new STT metrics (total time, audio duration, RTF) in Live Mode.
astrbot/dashboard/services/live_chat_service.py Measures STT timing and emits stt_total_time, stt_audio_duration, and stt_rtf metrics.
astrbot/core/pipeline/preprocess_stage/stage.py Adds STT duration + audio duration probing and records detailed STT stats into event.trace.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +47 to +51
<span v-if="metrics.stt_total_time">STT Total Latency: {{ (metrics.stt_total_time *
1000).toFixed(0) }}ms</span>
<span v-if="metrics.stt_audio_duration">STT Audio Duration: {{ (metrics.stt_audio_duration *
1000).toFixed(0) }}ms</span>
<span v-if="metrics.stt_rtf">STT RTF: {{ metrics.stt_rtf.toFixed(2) }}</span>
Comment on lines +888 to +890
stt_start = time.time()
user_text = await stt_provider.get_text(audio_path)
stt_duration = time.time() - stt_start
Comment on lines +200 to 204
stt_start = time.time()
status = "failed"
retry = 5
for i in range(retry):
try:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants