Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
#5707: keep the plan's included voice on Flash, since its relay takes Flash and Turbo only
milind-sonibbde76eb2f86
diff --git a/server/tts/elevenlabs.test.ts b/server/tts/elevenlabs.test.tsindex e1f0d3fe8b..d46fbc07ec 100644--- a/server/tts/elevenlabs.test.ts+++ b/server/tts/elevenlabs.test.ts@@ -13,6 +13,10 @@ describe("ElevenLabs speech model", () => {expect(speechModel("ᲒᲐᲛᲐᲠᲯᲝᲑᲐ")).toBe("eleven_v3");});+ it("stays on Flash through the plan's included voice, whose relay takes Flash and Turbo only", () => {+ expect(speechModel("สวัสดีครับ วันนี้อากาศดี", true)).toBe("eleven_flash_v2_5");+ });+it("keeps Flash for languages it speaks", () => {for (const text of ["Hello there", "こんにちは", "你好", "नमस्ते", "Xin chào", "Привет", "مرحبا", "வணக்கம்"]) {expect(speechModel(text)).toBe("eleven_flash_v2_5");diff --git a/server/tts/elevenlabs.ts b/server/tts/elevenlabs.tsindex cde5b5e76b..dc3bc2db68 100644--- a/server/tts/elevenlabs.ts+++ b/server/tts/elevenlabs.ts@@ -5,9 +5,10 @@ import { userErrorThrown } from "../user-errors.ts";const MODEL = "eleven_flash_v2_5";// Flash v2.5 has no Thai, Bengali, Hebrew, Georgian, Armenian, Gujarati, Punjabi, Telugu, Kannada or Malayalam; Eleven v3-// speaks them. Text in one of their scripts goes to v3, everything else stays on the faster Flash.+// speaks them. Text in one of their scripts goes to v3, everything else stays on the faster Flash. The plan's included+// voice relay takes Flash and Turbo only, so through it every line stays on Flash.const BEYOND_FLASH = /[\u0E00-\u0E7F\u0980-\u09FF\u0590-\u05FF\u10A0-\u10FF\u1C90-\u1CBF\u0530-\u058F\u0A80-\u0AFF\u0A00-\u0A7F\u0C00-\u0C7F\u0C80-\u0CFF\u0D00-\u0D7F]/;-export const speechModel = (text: string): string => (BEYOND_FLASH.test(text) ? "eleven_v3" : MODEL);+export const speechModel = (text: string, included = false): string => (!included && BEYOND_FLASH.test(text) ? "eleven_v3" : MODEL);const HEARING_MODEL = "scribe_v2";// 64kbps mono is indistinguishable for speech and a third of the bytesconst FORMAT = "mp3_44100_64";@@ -155,7 +156,7 @@ export interface Synthesis {audio: Promise<Audio>;}-export function synthesize(text: string, voiceId: string, key: string, api: string): Synthesis {+export function synthesize(text: string, voiceId: string, key: string, api: string, included = false): Synthesis {const firstAudio = withResolvers<Audio>();const audio = withResolvers<Audio>();// Callers may consume only `audio`: a failure before the first chunk must not become an unhandled rejection.@@ -165,7 +166,7 @@ export function synthesize(text: string, voiceId: string, key: string, api: striconst res = await fetch(`${api}/text-to-speech/${encodeURIComponent(voiceId)}/stream?output_format=${FORMAT}`, {method: "POST",headers: { "xi-api-key": key, "content-type": "application/json", accept: "audio/mpeg" },- body: JSON.stringify({ text, model_id: speechModel(text) }),+ body: JSON.stringify({ text, model_id: speechModel(text, included) }),redirect: "error",signal: AbortSignal.timeout(60_000),});diff --git a/server/tts/index.ts b/server/tts/index.tsindex f6c66b3c56..9e90c82ed5 100644--- a/server/tts/index.ts+++ b/server/tts/index.ts@@ -226,7 +226,7 @@ export function speak(cfg: AppConfig, text: string, voiceId?: string, run?: systif (!credential) throw new NoVoiceConfigured("key");const voice = voiceId || cfg.tts?.voice;if (!voice) throw new NoVoiceConfigured("voice");- return elevenlabs.synthesize(text, voice, credential.token, credential.api).audio;+ return elevenlabs.synthesize(text, voice, credential.token, credential.api, credential.included).audio;}export type { Voice } from "./elevenlabs.ts";