Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Fix emoji reading in chat read-aloud (#16480)
rugved8607346f423d1025
diff --git a/studio/frontend/package-lock.json b/studio/frontend/package-lock.jsonindex 791ddf042d7..353b3422af1 100644--- a/studio/frontend/package-lock.json+++ b/studio/frontend/package-lock.json@@ -48,6 +48,7 @@"decode-named-character-reference": "1.3.0","dexie": "^4.3.0","dingbat-to-unicode": "^1.0.1",+ "emoji-regex": "11.0.0","fflate": "0.8.3","js-yaml": "^4.3.2","katex": "^0.16.28",@@ -8249,11 +8250,10 @@"license": "ISC"},"node_modules/emoji-regex": {- "version": "8.0.0",- "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",- "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",- "license": "MIT",- "optional": true+ "version": "11.0.0",+ "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-11.0.0.tgz",+ "integrity": "sha512-2qQtc7syPcJmvF7BfKxBvwgvhzDth6u3q23+Jr4JOQUcmMGgmj7B4/ePZ2DmOhrrb77S8kMNHq2kilVASysfqA==",+ "license": "MIT"},"node_modules/enhanced-resolve": {"version": "5.21.0",@@ -12101,6 +12101,13 @@"node": ">=8"}},+ "node_modules/string-width/node_modules/emoji-regex": {+ "version": "8.0.0",+ "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",+ "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",+ "license": "MIT",+ "optional": true+ },"node_modules/string-width/node_modules/strip-ansi": {"version": "6.0.1","resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",diff --git a/studio/frontend/package.json b/studio/frontend/package.jsonindex 62305ddf182..6c3ec82bddf 100644--- a/studio/frontend/package.json+++ b/studio/frontend/package.json@@ -63,6 +63,7 @@"decode-named-character-reference": "1.3.0","dexie": "^4.3.0","dingbat-to-unicode": "^1.0.1",+ "emoji-regex": "11.0.0","fflate": "0.8.3","js-yaml": "^4.3.2","katex": "^0.16.28",diff --git a/studio/frontend/src/features/chat/adapters/studio-speech-synthesis-adapter.ts b/studio/frontend/src/features/chat/adapters/studio-speech-synthesis-adapter.tsindex ebc131c1220..4422eaf1b5e 100644--- a/studio/frontend/src/features/chat/adapters/studio-speech-synthesis-adapter.ts+++ b/studio/frontend/src/features/chat/adapters/studio-speech-synthesis-adapter.ts@@ -119,7 +119,6 @@ function langBase(tag: string): string {const MAX_CURATED_VOICES = 20;-/** Filter, rank and cap voices; the selected voice is always kept. */export function curateSystemVoices(voices: SpeechSynthesisVoice[],selectedVoiceURI?: string,@@ -261,7 +260,6 @@ function readAloudError(return new Error(detail);}-/** Generate speech via the loaded TTS audio model; returns a WAV data URL. */export async function generateStudioTtsAudio(text: string,signal?: AbortSignal,@@ -421,7 +419,6 @@ function speakWithBackendAudio(let audioUrl: string | null = null;let cancelled = false;- // Release the element and its multi-MB WAV data URL as soon as playback ends.const cleanup = () => {if (audio) {audio.pause();@@ -477,7 +474,6 @@ function speakWithBackendAudio(};}-/** Engines: "system" (speechSynthesis), "studio" (local TTS), "custom" (a connection). */export class StudioSpeechSynthesisAdapter implements SpeechSynthesisAdapter {static systemVoicesSupported(): boolean {return (@@ -504,7 +500,6 @@ export class StudioSpeechSynthesisAdapter implements SpeechSynthesisAdapter {error?: unknown,) => {if (res.status.type === "ended") return;- // A cancelled or interrupted utterance is a normal stop and must not toast.if (reason === "error" &&error !== "interrupted" &&@@ -540,7 +535,11 @@ export class StudioSpeechSynthesisAdapter implements SpeechSynthesisAdapter {};},};-+ if (!text.trim()) {+ cancelImpl = () => {};+ handleEnd("finished");+ return res;+ }if (ttsEngine !== "system" ||!StudioSpeechSynthesisAdapter.systemVoicesSupported()diff --git a/studio/frontend/src/features/chat/utils/speech-text.ts b/studio/frontend/src/features/chat/utils/speech-text.tsindex f5a72de712a..595b5deb8e2 100644--- a/studio/frontend/src/features/chat/utils/speech-text.ts+++ b/studio/frontend/src/features/chat/utils/speech-text.ts@@ -2,6 +2,7 @@// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0import { decodeNamedCharacterReference } from "decode-named-character-reference";+import emojiRegex from "emoji-regex";import type { Nodes, Root, RootContent } from "mdast";import { fromMarkdown } from "mdast-util-from-markdown";import { gfmFromMarkdown } from "mdast-util-gfm";@@ -23,6 +24,27 @@ const LINE_TAGS = new Set(" ",),);+function removeTtsEmojis(text: string): string {+ let removed = false;+ const cleaned = text.replace(emojiRegex(), (emoji, offset, source) => {+ if (+ source[offset + emoji.length] === "\uFE0E" ||+ ([...emoji].length === 1 &&+ /\p{Emoji}/u.test(emoji) &&+ !/\p{Emoji_Presentation}/u.test(emoji))+ ) {+ return emoji;+ }+ removed = true;+ return " ";+ });+ return removed+ ? cleaned+ .replace(/[ \t]+([,.;:!?])/g, "$1")+ .replace(/[ \t]{2,}/g, " ")+ .trim()+ : text;+}/** The words a markdown reply shows, for read-aloud: voices speak raw markup ("asterisk asterisk", #12547). */export function markdownToSpeechText(markdown: string): string {@@ -34,7 +56,7 @@ export function markdownToSpeechText(markdown: string): string {mdastExtensions: [gfmFromMarkdown(), mathFromMarkdown()],});} catch {- return markdown;+ return removeTtsEmojis(markdown);}const out: string[] = [];const notes: string[] = [];@@ -46,7 +68,9 @@ export function markdownToSpeechText(markdown: string): string {false,);}- return [...out, ...notes].filter((block) => block.length > 0).join("\n");+ return removeTtsEmojis(+ [...out, ...notes].filter((block) => block.length > 0).join("\n"),+ );}function collectBlocks(@@ -68,7 +92,10 @@ function collectBlocks(return;case "table":for (const row of node.children) {- out.push(sentence(row.children.map(inline).join(", ")));+ const cells = row.children.map((cell) => removeTtsEmojis(inline(cell)));+ if (cells.some((cell) => cell.trim())) {+ out.push(sentence(cells.join(", ")));+ }}return;// The sanitizer unwraps raw HTML, so its text shows on the page.@@ -138,7 +165,7 @@ function htmlText(html: string): string {}function sentence(text: string): string {- const trimmed = text.trim();+ const trimmed = removeTtsEmojis(text).trim();if (!trimmed || /[.!?:;,…]$/.test(trimmed)) return trimmed;return `${trimmed}.`;}diff --git a/studio/frontend/tests/speech-text.test.ts b/studio/frontend/tests/speech-text.test.tsindex 9e392f9c4e1..ea8bee4ef48 100644--- a/studio/frontend/tests/speech-text.test.ts+++ b/studio/frontend/tests/speech-text.test.ts@@ -114,3 +114,61 @@ test("HTML tags keep the word boundaries the page shows", () => {);assert.equal(markdownToSpeechText("<div>H<sub>2</sub>O</div>"), "H2O");});++test("read-aloud skips emoji sequences but preserves surrounding words", () => {+ const spoken = markdownToSpeechText(+ "Japan 🇯🇵 developer 👩💻 thumbs 👍🏽 heart ❤️",+ );++ assert.match(spoken, /Japan\s+developer\s+thumbs\s+heart/);++ for (const emoji of ["🇯🇵", "👩💻", "👍🏽", "❤️"]) {+ assert.equal(spoken.includes(emoji), false);+ }+});++test("read-aloud handles emoji-only messages", () => {+ assert.equal(markdownToSpeechText("😀 👨💻 🇯🇵").trim(), "");+ for (const input of [+ "# 😀",+ "- 😀\n- 👍",+ "1. 😀",+ "| 😀 | 😘 |\n| --- | --- |\n| 🥰 | ❤️ |",+ ]) {+ assert.equal(markdownToSpeechText(input), "", input);+ }+});++test("read-aloud preserves word boundaries around emojis", () => {+ for (const input of [+ "Hello😀world",+ "Hello😀😀world",+ "Hello👩💻👍🏽world",+ ]) {+ assert.equal(markdownToSpeechText(input), "Hello world", input);+ }+});++test("read-aloud cleans the reported German and English replies", () => {+ assert.equal(+ markdownToSpeechText("Hallo! 🥰❤️ Schön, dass du da bist. 😘"),+ "Hallo! Schön, dass du da bist.",+ );+ assert.equal(+ markdownToSpeechText("Hello! 🥰❤️ It's wonderful to see you. 😘"),+ "Hello! It's wonderful to see you.",+ );+});++test("read-aloud preserves ordinary symbols and whitespace without emojis", () => {+ assert.equal(+ markdownToSpeechText("© 2026 ® ™ ℹ 123 # *"),+ "© 2026 ® ™ ℹ 123 # *",+ );+ assert.equal(markdownToSpeechText("`two spaces`"), "two spaces");+ assert.equal(markdownToSpeechText("word🥰❤️, next"), "word, next");+ assert.equal(markdownToSpeechText("$A ↔ B$"), "A ↔ B");+ assert.equal(markdownToSpeechText("Sex: ♀ / ♂"), "Sex: ♀ / ♂");+ assert.equal(markdownToSpeechText("Watch ⌚\uFE0E"), "Watch ⌚\uFE0E");+ assert.equal(markdownToSpeechText("©️ ®️ ™️ ℹ️"), "");+});