Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(voice): add live voice prompt and types

Steven Enamakele8613d3a2c82
diff --git a/crates/openhuman-core/src/voice/live/prompt.md b/crates/openhuman-core/src/voice/live/prompt.md
new file mode 100644
index 0000000000..68522d39ab
--- /dev/null
+++ b/crates/openhuman-core/src/voice/live/prompt.md
@@ -0,0 +1,15 @@
+You are Tiny, the voice of OpenHuman, talking with the user out loud in real time.
+
+How to speak:
+- Keep every reply short and natural to say aloud: one to three sentences unless the user asks for detail.
+- No markdown, lists, code blocks, emoji, URLs or symbols that do not read well when spoken.
+- Say numbers, dates and times the way a person would.
+- If the user interrupts you, stop and listen; do not repeat what you already said.
+
+How to act:
+- You can use OpenHuman's tools. Use them whenever the user asks you to look something up, change something, or do something on their behalf, instead of guessing.
+- Before an action that sends, deletes, pays for or changes something important, say briefly what you are about to do. The app may ask the user to approve it.
+- When a tool fails or is not allowed, say so plainly and suggest what the user can do.
+- While a tool runs for more than a moment, say a few words ("one moment, checking your calendar") so the user is not left in silence.
+
+What you say is saved to the user's current conversation, so keep it accurate.
diff --git a/crates/openhuman-core/src/voice/live/types.rs b/crates/openhuman-core/src/voice/live/types.rs
new file mode 100644
index 0000000000..339e5ff9e6
--- /dev/null
+++ b/crates/openhuman-core/src/voice/live/types.rs
@@ -0,0 +1,142 @@
+//! Wire types for live voice sessions: RPC payloads and WebSocket frames.
+
+use serde::{Deserialize, Serialize};
+
+pub use crate::config::schema::voice_live::{
+ ElevenLabsLiveSettings, GeminiLiveSettings, LiveVoiceConfig, SarvamLiveSettings,
+};
+
+/// How a provider is reached.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub enum LiveProviderKind {
+ /// Through the TinyHumans backend; no user key.
+ Hosted,
+ /// With the user's own API key.
+ Byok,
+}
+
+/// One live provider, as the settings UI shows it.
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct LiveProviderInfo {
+ /// Stable id (`gemini-hosted`, `elevenlabs-hosted`, `gemini`, `sarvam`).
+ pub id: String,
+ /// Display label.
+ pub label: String,
+ /// Hosted or bring-your-own-key.
+ pub kind: LiveProviderKind,
+ /// Whether the provider can be used right now (a key is stored, or the
+ /// backend is reachable with a credential).
+ pub configured: bool,
+ /// The `provider:<slug>` key a BYOK provider reads, if any.
+ pub key_slug: Option<String>,
+ /// Voices the provider offers.
+ pub voices: Vec<String>,
+ /// Languages the provider speaks.
+ pub languages: Vec<String>,
+}
+
+/// `voice.live_providers` result.
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct LiveProvidersResponse {
+ pub default_provider: String,
+ pub providers: Vec<LiveProviderInfo>,
+}
+
+/// `voice.live_settings_set` params: any subset of the settings.
+#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
+pub struct LiveSettingsPatch {
+ #[serde(default)]
+ pub default_provider: Option<String>,
+ #[serde(default)]
+ pub gemini: Option<GeminiLiveSettings>,
+ #[serde(default)]
+ pub sarvam: Option<SarvamLiveSettings>,
+ #[serde(default)]
+ pub elevenlabs: Option<ElevenLabsLiveSettings>,
+}
+
+/// `voice.live_test_provider` result.
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct LiveTestResult {
+ pub ok: bool,
+ pub latency_ms: Option<u64>,
+ pub error: Option<String>,
+}
+
+/// A JSON frame the client sends on `/ws/live-voice`. Audio travels as binary
+/// frames (PCM16 little-endian mono at `input_sample_rate`).
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+#[serde(tag = "type", rename_all = "snake_case")]
+pub enum ClientFrame {
+ /// Opens the session; must be the first frame.
+ Start {
+ #[serde(default)]
+ provider: Option<String>,
+ #[serde(default)]
+ thread_id: Option<String>,
+ #[serde(default = "default_input_rate")]
+ input_sample_rate: u32,
+ },
+ /// A typed user message.
+ Text { text: String },
+ /// Stop the agent's current reply.
+ Interrupt,
+ /// End the session.
+ Stop,
+}
+
+fn default_input_rate() -> u32 {
+ 16_000
+}
+
+/// Who a transcript belongs to.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub enum TranscriptRole {
+ User,
+ Agent,
+}
+
+/// A JSON frame the core sends. Agent audio travels as binary frames
+/// (PCM16 little-endian mono at `output_sample_rate`).
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+#[serde(tag = "type", rename_all = "snake_case")]
+pub enum ServerFrame {
+ Ready {
+ session_id: Option<String>,
+ provider: String,
+ output_sample_rate: u32,
+ thread_id: Option<String>,
+ },
+ Transcript {
+ role: TranscriptRole,
+ text: String,
+ #[serde(rename = "final")]
+ is_final: bool,
+ },
+ ToolStarted {
+ call_id: String,
+ name: String,
+ },
+ ToolFinished {
+ call_id: String,
+ name: String,
+ ok: bool,
+ cancelled: bool,
+ },
+ Interrupted,
+ TurnComplete,
+ Error {
+ code: String,
+ message: String,
+ fatal: bool,
+ },
+ Closed {
+ reason: String,
+ },
+}
+
+#[cfg(test)]
+#[path = "types_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/voice/live/types_tests.rs b/crates/openhuman-core/src/voice/live/types_tests.rs
new file mode 100644
index 0000000000..f59b73d796
--- /dev/null
+++ b/crates/openhuman-core/src/voice/live/types_tests.rs
@@ -0,0 +1,49 @@
+use super::*;
+use serde_json::json;
+
+#[test]
+fn client_frames_use_snake_case_tags_and_defaults() {
+ let start: ClientFrame = serde_json::from_value(json!({"type": "start"})).unwrap();
+ assert_eq!(
+ start,
+ ClientFrame::Start {
+ provider: None,
+ thread_id: None,
+ input_sample_rate: 16_000
+ }
+ );
+ let text: ClientFrame = serde_json::from_value(json!({"type": "text", "text": "hi"})).unwrap();
+ assert_eq!(text, ClientFrame::Text { text: "hi".into() });
+ assert_eq!(
+ serde_json::from_value::<ClientFrame>(json!({"type": "interrupt"})).unwrap(),
+ ClientFrame::Interrupt
+ );
+ assert!(serde_json::from_value::<ClientFrame>(json!({"type": "nope"})).is_err());
+}
+
+#[test]
+fn server_frames_serialize_the_documented_shape() {
+ let frame = ServerFrame::Transcript {
+ role: TranscriptRole::Agent,
+ text: "hi".into(),
+ is_final: true,
+ };
+ assert_eq!(
+ serde_json::to_value(frame).unwrap(),
+ json!({"type": "transcript", "role": "agent", "text": "hi", "final": true})
+ );
+ assert_eq!(
+ serde_json::to_value(ServerFrame::TurnComplete).unwrap(),
+ json!({"type": "turn_complete"})
+ );
+ assert_eq!(
+ serde_json::to_value(ServerFrame::ToolFinished {
+ call_id: "c".into(),
+ name: "n".into(),
+ ok: false,
+ cancelled: true
+ })
+ .unwrap(),
+ json!({"type": "tool_finished", "call_id": "c", "name": "n", "ok": false, "cancelled": true})
+ );
+}