Skip to content

Agent Zero AI framework

feature: speech to text settings

Alessandro89b848312b6f
diff --git a/python/helpers/settings.py b/python/helpers/settings.py
index fe18528c4..867969ab7 100644
--- a/python/helpers/settings.py
+++ b/python/helpers/settings.py
@@ -39,6 +39,13 @@ class Settings(TypedDict):
rfc_url: str
rfc_password: str
+ stt_model_size: str
+ stt_language: str
+ stt_silence_threshold: float
+ stt_silence_duration: int
+ stt_waiting_timeout: int
+ stt_min_speech_duration: int
+
class PartialSettings(Settings, total=False):
pass
@@ -413,12 +420,82 @@ def convert_out(settings: Settings) -> SettingsOutput:
"fields": dev_fields,
}
+ # Speech to text section
+ stt_fields: list[SettingsField] = []
+
+ stt_fields.append({
+ "id": "stt_model_size",
+ "title": "Model Size",
+ "description": "Select the speech recognition model size",
+ "type": "select",
+ "value": settings["stt_model_size"],
+ "options": [
+ {"value": "tiny", "label": "Tiny (39M, English)"},
+ {"value": "base", "label": "Base (74M, English)"},
+ {"value": "small", "label": "Small (244M, English)"},
+ {"value": "medium", "label": "Medium (769M, English)"},
+ {"value": "large", "label": "Large (1.5B, Multilingual)"},
+ {"value": "turbo", "label": "Turbo (Multilingual)"}
+ ]
+ })
+
+ stt_fields.append({
+ "id": "stt_language",
+ "title": "Language Code",
+ "description": "Language code (e.g. en, fr, it)",
+ "type": "input",
+ "value": settings["stt_language"]
+ })
+
+ stt_fields.append({
+ "id": "stt_silence_threshold",
+ "title": "Silence threshold",
+ "description": "Silence detection threshold. Lower values are more sensitive.",
+ "type": "range",
+ "min": 0,
+ "max": 1,
+ "step": 0.01,
+ "value": settings["stt_silence_threshold"]
+ })
+
+ stt_fields.append({
+ "id": "stt_silence_duration",
+ "title": "Silence duration (ms)",
+ "description": "Duration of silence before the server considers speaking to have ended.",
+ "type": "input",
+ "value": settings["stt_silence_duration"]
+ })
+
+ stt_fields.append({
+ "id": "stt_waiting_timeout",
+ "title": "Waiting timeout (ms)",
+ "description": "Duration before the server closes the microphone.",
+ "type": "input",
+ "value": settings["stt_waiting_timeout"]
+ })
+
+ stt_fields.append({
+ "id": "stt_min_speech_duration",
+ "title": "Prefix padding (ms)",
+ "description": "Minimum duration of audio to be included in the stream before speech was recognized.",
+ "type": "input",
+ "value": settings["stt_min_speech_duration"]
+ })
+
+ stt_section: SettingsSection = {
+ "title": "Speech to Text",
+ "description": "Voice transcription preferences and server turn detection settings.",
+ "fields": stt_fields
+ }
+
+ # Add the section to the result
result: SettingsOutput = {
"sections": [
agent_section,
chat_model_section,
util_model_section,
embed_model_section,
+ stt_section,
api_keys_section,
auth_section,
dev_section,
@@ -443,9 +520,7 @@ def convert_in(settings: dict) -> Settings:
if "fields" in section:
for field in section["fields"]:
if field["id"].endswith("_kwargs"):
- current[field["id"]] = _env_to_dict(
- field["value"]
- ) # parse KWARGS from env format
+ current[field["id"]] = _env_to_dict(field["value"])
elif field["id"].startswith("api_key_"):
current["api_keys"][field["id"]] = field["value"]
else:
@@ -518,6 +593,11 @@ def get_embedding_model(settings: Settings | None = None) -> Embeddings:
**settings["embed_model_kwargs"],
)
+def get_speech_settings(settings: Settings | None = None) -> dict:
+ if not settings:
+ settings = get_settings()
+ return settings["speech_to_text"]
+
def _read_settings_file() -> Settings | None:
if os.path.exists(SETTINGS_FILE):
@@ -573,6 +653,12 @@ def _get_default_settings() -> Settings:
agent_knowledge_subdir="custom",
rfc_url="http://localhost:55080",
rfc_password="",
+ stt_model_size="tiny",
+ stt_language="en",
+ stt_silence_threshold=0.15,
+ stt_silence_duration=1000,
+ stt_waiting_timeout=2000,
+ stt_min_speech_duration=500
)
diff --git a/webui/js/settings.js b/webui/js/settings.js
index bd8854982..8be6fd542 100644
--- a/webui/js/settings.js
+++ b/webui/js/settings.js
@@ -91,6 +91,7 @@ function getIconName(title) {
'Chat Model': 'chat-model',
'Utility model': 'utility-model',
'Embedding Model': 'embed-model',
+ 'Speech to Text': 'voice',
'API Keys': 'api-keys',
'Authentication': 'auth',
'Development': 'dev'
diff --git a/webui/js/speech.js b/webui/js/speech.js
index 7d5e9a1ba..d7118b131 100644
--- a/webui/js/speech.js
+++ b/webui/js/speech.js
@@ -35,15 +35,36 @@ class MicrophoneInput {
this.hasStartedRecording = false;
this.analysisFrame = null;
+ // Initialize with defaults
this.options = {
modelSize: 'tiny',
language: 'en',
silenceThreshold: 0.15,
silenceDuration: 1000,
waitingTimeout: 2000,
- minSpeechDuration: 500,
- ...options
+ minSpeechDuration: 500
};
+
+ // Fetch settings from server
+ this.loadSettings();
+ }
+
+ async loadSettings() {
+ try {
+ const response = await fetch('/settings_get');
+ const data = await response.json();
+ const sttSettings = data.settings.sections.find(s => s.title === 'Speech to Text');
+
+ if (sttSettings) {
+ // Update options from server settings
+ sttSettings.fields.forEach(field => {
+ const key = field.id.split('.')[1]; // speech_to_text.model_size -> model_size
+ this.options[key] = field.value;
+ });
+ }
+ } catch (error) {
+ console.error('Failed to load speech settings:', error);
+ }
}
get status() {
@@ -314,13 +335,6 @@ async function initializeMicrophoneInput() {
await sendMessage();
}
}
- },
- {
- modelSize: 'tiny',
- language: 'en',
- silenceThreshold: 0.07,
- silenceDuration: 1000,
- waitingTimeout: 1500
}
);
microphoneInput.status = Status.ACTIVATING;
@@ -439,4 +453,11 @@ class Speech {
}
export const speech = new Speech();
-window.speech = speech
\ No newline at end of file
+window.speech = speech
+
+// Add event listener for settings changes
+document.addEventListener('settings-updated', async () => {
+ if (microphoneInput) {
+ await microphoneInput.loadSettings();
+ }
+});
\ No newline at end of file
diff --git a/webui/public/voice.svg b/webui/public/voice.svg
new file mode 100644
index 000000000..19a7d2abb
--- /dev/null
+++ b/webui/public/voice.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" id="Layer_1" x="0" y="0" version="1.1" viewBox="0 0 22.6 21.2"><style>.st0{fill:none;stroke:#000;stroke-width:.5;stroke-linecap:round;stroke-miterlimit:10}</style><g id="XMLID_00000031915645942353647240000017236973318540577665_"><path d="m11.8 7.9 2.1 4.6c.2.3-.1.7-.5.7h-1.7v3.4c0 .7-.6 1.3-1.3 1.3H4.2M7.7 20.8V18M4.2.3c4.2 0 7.6 3.4 7.6 7.6" class="st0"/><path d="M11.8 15.8h-1.4l-.4-.4" class="st0"/></g><path d="M14.2 15.7c.8.8.8 2 0 2.8M15.6 14.8c1.3 1.3 1.3 3.3 0 4.6M17 13.8c1.8 1.8 1.8 4.7 0 6.5" class="st0"/></svg>
\ No newline at end of file