mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 22:31:36 +00:00
fix: honor audio_as_voice streaming + parse tests (#490) (thanks @jarvis-medmatic)
This commit is contained in:
19
src/media/parse.test.ts
Normal file
19
src/media/parse.test.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { splitMediaFromOutput } from "./parse.js";
|
||||
|
||||
describe("splitMediaFromOutput", () => {
|
||||
it("detects audio_as_voice tag and strips it", () => {
|
||||
const result = splitMediaFromOutput("Hello [[audio_as_voice]] world");
|
||||
expect(result.audioAsVoice).toBe(true);
|
||||
expect(result.text).toBe("Hello world");
|
||||
});
|
||||
|
||||
it("keeps audio_as_voice detection stable across calls", () => {
|
||||
const input = "Hello [[audio_as_voice]]";
|
||||
const first = splitMediaFromOutput(input);
|
||||
const second = splitMediaFromOutput(input);
|
||||
expect(first.audioAsVoice).toBe(true);
|
||||
expect(second.audioAsVoice).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -34,6 +34,7 @@ function isInsideFence(
|
||||
|
||||
// Regex to detect [[audio_as_voice]] tag
|
||||
const AUDIO_AS_VOICE_RE = /\[\[audio_as_voice\]\]/gi;
|
||||
const AUDIO_AS_VOICE_TEST_RE = /\[\[audio_as_voice\]\]/i;
|
||||
|
||||
export function splitMediaFromOutput(raw: string): {
|
||||
text: string;
|
||||
@@ -123,7 +124,7 @@ export function splitMediaFromOutput(raw: string): {
|
||||
.trim();
|
||||
|
||||
// Detect and strip [[audio_as_voice]] tag
|
||||
const hasAudioAsVoice = AUDIO_AS_VOICE_RE.test(cleanedText);
|
||||
const hasAudioAsVoice = AUDIO_AS_VOICE_TEST_RE.test(cleanedText);
|
||||
if (hasAudioAsVoice) {
|
||||
cleanedText = cleanedText
|
||||
.replace(AUDIO_AS_VOICE_RE, "")
|
||||
|
||||
Reference in New Issue
Block a user