Skip to content

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

feat(channels): add voice host callbacks for transcription and speech

Steven Enamakela6c6287c0863
diff --git a/Cargo.lock b/Cargo.lock
index d6b8acfd98..ff5fbe4f86 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5490,7 +5490,7 @@ dependencies = [
"tinytools",
"tinytools-agent",
"tinytools-std",
- "tinyvoice-bus",
+ "tinyvoice-bus 0.1.4",
"tinywallet",
"tinywallet-bus",
"tokio",
@@ -8764,6 +8764,7 @@ dependencies = [
"hmac 0.13.0",
"lettre",
"mail-parser",
+ "mime",
"parking_lot",
"prost",
"rand 0.10.2",
@@ -8798,14 +8799,11 @@ dependencies = [
name = "tinychannels-bus"
version = "0.1.34"
dependencies = [
- "anyhow",
- "async-trait",
"base64 0.23.1",
"schemars",
"serde",
"serde_json",
"thiserror 2.0.20",
- "tokio",
]
[[package]]
@@ -8814,6 +8812,8 @@ version = "0.1.34"
dependencies = [
"anyhow",
"async-trait",
+ "base64 0.23.1",
+ "futures-util",
"hex",
"log",
"serde",
@@ -8827,6 +8827,7 @@ dependencies = [
"tinystoragedrivers-busproxy",
"tinystoragedrivers-client",
"tinystoragedrivers-core",
+ "tinyvoice-bus 0.1.4 (git+https://github.com/tinyhumansai/tinyvoice?rev=7a8e3ac5b31a11e9c061541b336c666ee10fa190)",
"tokio",
"tracing",
"uuid",
@@ -9871,7 +9872,7 @@ dependencies = [
"serde",
"serde_json",
"thiserror 2.0.20",
- "tinyvoice-bus",
+ "tinyvoice-bus 0.1.4",
"tokio",
]
@@ -9884,6 +9885,16 @@ dependencies = [
"thiserror 2.0.20",
]
+[[package]]
+name = "tinyvoice-bus"
+version = "0.1.4"
+source = "git+https://github.com/tinyhumansai/tinyvoice?rev=7a8e3ac5b31a11e9c061541b336c666ee10fa190#7a8e3ac5b31a11e9c061541b336c666ee10fa190"
+dependencies = [
+ "serde",
+ "serde_json",
+ "thiserror 2.0.20",
+]
+
[[package]]
name = "tinyvoice-hotkey-win"
version = "0.1.0"
@@ -9908,7 +9919,7 @@ dependencies = [
"tinybus-module",
"tinytools",
"tinyvoice",
- "tinyvoice-bus",
+ "tinyvoice-bus 0.1.4",
"tinyvoice-hotkey-win",
"tokio",
"x11rb",
diff --git a/crates/openhuman-core/src/channels/host/adapters.rs b/crates/openhuman-core/src/channels/host/adapters.rs
index ac5b8cbeba..ca4243f053 100644
--- a/crates/openhuman-core/src/channels/host/adapters.rs
+++ b/crates/openhuman-core/src/channels/host/adapters.rs
@@ -69,27 +69,11 @@ impl VoiceTranscriber {
&self,
request: tinychannels_bus::HostTranscriptionRequest,
) -> anyhow::Result<tinychannels_bus::HostTranscriptionResult> {
- let provider = crate::voice::effective_stt_provider(&self.config);
- tracing::debug!(
- "{LOG_PREFIX} transcribe provider={provider} bytes_b64={}",
- request.audio_base64.len()
- );
- let stt = crate::voice::create_stt_provider(&provider, "", &self.config)?;
- let outcome = stt
- .transcribe(
- &self.config,
- &request.audio_base64,
- request.mime_type.as_deref(),
- request.file_name.as_deref(),
- request.language.as_deref(),
- )
- .await
- .map_err(|e| anyhow::anyhow!(e))?;
- Ok(tinychannels_bus::HostTranscriptionResult {
- text: outcome.value.text,
- language: request.language,
- duration_secs: None,
- })
+ super::voice::ChannelVoiceHost {
+ config: Arc::clone(&self.config),
+ }
+ .transcribe_host(request)
+ .await
}
}
diff --git a/crates/openhuman-core/src/channels/host/mod.rs b/crates/openhuman-core/src/channels/host/mod.rs
index d5746235fe..c0b5cfa0f5 100644
--- a/crates/openhuman-core/src/channels/host/mod.rs
+++ b/crates/openhuman-core/src/channels/host/mod.rs
@@ -6,6 +6,7 @@
mod adapters;
mod channel_events;
pub(crate) mod remote_control;
+pub(crate) mod voice;
pub(crate) use adapters::{ConfigAllowlistStore, OpenHumanEventSink, VoiceTranscriber};
#[cfg(test)]
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
index 7bd943999b..49e939da66 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
@@ -88,6 +88,7 @@ pub(crate) async fn process_channel_runtime_message(
let history_key = prepared.history_key;
let mut envelope = prepared.envelope;
envelope.access.delivered_via_upstream_relay = authenticated_relay;
+ crate::channels::host::voice::record_inbound_envelope(&envelope);
println!(
" 💬 [{}] from {}: {}",
diff --git a/crates/openhuman-core/src/channels/runtime/startup/callback.rs b/crates/openhuman-core/src/channels/runtime/startup/callback.rs
index 2bfe27c65f..d30d01ac59 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/callback.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/callback.rs
@@ -6,8 +6,9 @@ use crate::config::Config;
use std::sync::{Arc, OnceLock, Weak};
use tinybus::{Error, Result};
use tinychannels_bus::{
- ChannelBackendRequest, ChannelBackendResult, HostEventPublication, HostTranscriptionRequest,
- HostTranscriptionResult,
+ ChannelBackendRequest, ChannelBackendResult, HostEventPublication, HostSpeechSynthesisRequest,
+ HostSpeechSynthesisResult, HostTranscriptionRequest, HostTranscriptionResult,
+ HostVoiceReplyPolicy, HostVoiceReplyPolicyRequest, HostVoiceTranscriptionRequest,
};
use tokio::sync::mpsc;
@@ -54,6 +55,12 @@ impl ChannelHostCallbacks {
Ok(())
}
+ fn voice(&self) -> crate::channels::host::voice::ChannelVoiceHost {
+ crate::channels::host::voice::ChannelVoiceHost {
+ config: Arc::clone(&self.config),
+ }
+ }
+
fn context(&self) -> Result<Arc<ChannelRuntimeContext>> {
self.context
.get()
@@ -133,12 +140,43 @@ impl ChannelHostCallbacks {
{
return Err(Error::failed("transcription callback exceeds its limit"));
}
- crate::channels::host::VoiceTranscriber {
- config: Arc::clone(&self.config),
+ self.voice()
+ .transcribe_host(request)
+ .await
+ .map_err(|_| Error::failed("channel transcription failed"))
+ }
+
+ async fn transcribe_voice(
+ &self,
+ request: HostVoiceTranscriptionRequest,
+ ) -> Result<HostTranscriptionResult> {
+ if serde_json::to_vec(&request).map_or(true, |bytes| bytes.len() > MAX_TRANSCRIPTION_BYTES)
+ {
+ return Err(Error::failed("transcription callback exceeds its limit"));
}
- .transcribe_host(request)
- .await
- .map_err(|_| Error::failed("channel transcription failed"))
+ self.voice()
+ .transcribe_voice(request)
+ .await
+ .map_err(|_| Error::failed("channel transcription failed"))
+ }
+
+ async fn synthesize_speech(
+ &self,
+ request: HostSpeechSynthesisRequest,
+ ) -> Result<HostSpeechSynthesisResult> {
+ Self::validate_callback_size(&request)?;
+ self.voice()
+ .synthesize_speech(request)
+ .await
+ .map_err(|_| Error::failed("channel speech synthesis failed"))
+ }
+
+ async fn get_voice_reply_policy(
+ &self,
+ request: HostVoiceReplyPolicyRequest,
+ ) -> Result<HostVoiceReplyPolicy> {
+ Self::validate_callback_size(&request)?;
+ Ok(self.voice().reply_policy(&request.scope))
}
async fn publish_event(&self, publication: HostEventPublication) -> Result<()> {
diff --git a/crates/openhuman-core/src/config/mod.rs b/crates/openhuman-core/src/config/mod.rs
index 0145a488a4..3d79789cbb 100644
--- a/crates/openhuman-core/src/config/mod.rs
+++ b/crates/openhuman-core/src/config/mod.rs
@@ -42,17 +42,18 @@ pub use schema::{
output_language_directive, runtime_proxy_config, set_runtime_proxy_config, AgentConfig,
AuditConfig, AutonomyConfig, BrowserComputerUseConfig, BrowserConfig, BudgetAction,
BudgetPeriod, BudgetPolicy, BudgetScope, CapabilityProviderConfig,
- CapabilityProviderTrustState, ChannelVoiceConfig, ChannelVoiceOverride, ChannelsConfig, CompactionSettings, CompactionStrategy,
- ComposioConfig, ComposioDirectBaseUrls, ComposioHostCredential, ComputerConfig, Config,
- ContextConfig, CostConfig, CronConfig, CurlConfig, DashboardConfig, DecisionModel,
- DelegateAgentConfig, DiagramViewerConfig, DictationActivationMode, DictationConfig,
- DiscordConfig, DockerRuntimeConfig, EmailConfig, EmbeddingRouteConfig, GitbooksConfig,
- HttpHeader, HttpRequestConfig, IMessageConfig, IntegrationToggle, IntegrationsConfig,
- LarkConfig, LegacySearchInputs, LinqConfig, LocalAiConfig, LocalJailConfig, MatrixConfig,
- McpAuthConfig, McpClientConfig, McpClientIdentityConfig, McpServerConfig, McpToolExposure,
- MemoryConfig, MemoryLayoutMode, ModelRouteConfig, MultimodalConfig, MultimodalFileConfig,
- ObservabilityConfig, OrchestratorModelConfig, PresentationMode, PrivacyConfig, PrivacyMode,
- ProviderRoute, ProxyConfig, ProxyScope, ReliabilityConfig, ResourceLimitsConfig, RuntimeConfig,
+ CapabilityProviderTrustState, ChannelVoiceConfig, ChannelVoiceOverride, ChannelsConfig,
+ CompactionSettings, CompactionStrategy, ComposioConfig, ComposioDirectBaseUrls,
+ ComposioHostCredential, ComputerConfig, Config, ContextConfig, CostConfig, CronConfig,
+ CurlConfig, DashboardConfig, DecisionModel, DelegateAgentConfig, DiagramViewerConfig,
+ DictationActivationMode, DictationConfig, DiscordConfig, DockerRuntimeConfig, EmailConfig,
+ EmbeddingRouteConfig, GitbooksConfig, HttpHeader, HttpRequestConfig, IMessageConfig,
+ IntegrationToggle, IntegrationsConfig, LarkConfig, LegacySearchInputs, LinqConfig,
+ LocalAiConfig, LocalJailConfig, MatrixConfig, McpAuthConfig, McpClientConfig,
+ McpClientIdentityConfig, McpServerConfig, McpToolExposure, MemoryConfig, MemoryLayoutMode,
+ ModelRouteConfig, MultimodalConfig, MultimodalFileConfig, ObservabilityConfig,
+ OrchestratorModelConfig, PresentationMode, PrivacyConfig, PrivacyMode, ProviderRoute,
+ ProxyConfig, ProxyScope, ReliabilityConfig, ResourceLimitsConfig, RuntimeConfig,
SandboxBackend, SandboxConfig, SchedulerConfig, SchedulerGateConfig, SchedulerGateMode,
SearchConfig, SearchEngineCredentials, SearchHostCredential, SearchProviderSettings,
SearxngConfig, SecretsConfig, SecurityConfig, ShellConfig, SlackConfig, StreamMode, SttEngine,
diff --git a/crates/openhuman-core/src/config/schema/channel_voice_tests.rs b/crates/openhuman-core/src/config/schema/channel_voice_tests.rs
index 5f2dc33329..5423779c6e 100644
--- a/crates/openhuman-core/src/config/schema/channel_voice_tests.rs
+++ b/crates/openhuman-core/src/config/schema/channel_voice_tests.rs
@@ -23,12 +23,18 @@ fn default_mode_is_mirror() {
#[test]
fn channel_override_beats_global() {
- assert_eq!(config().resolve_mode("telegram", "other"), VoiceReplyMode::Always);
+ assert_eq!(
+ config().resolve_mode("telegram", "other"),
+ VoiceReplyMode::Always
+ );
}
#[test]
fn thread_override_beats_channel() {
- assert_eq!(config().resolve_mode("telegram", "t-1"), VoiceReplyMode::Never);
+ assert_eq!(
+ config().resolve_mode("telegram", "t-1"),
+ VoiceReplyMode::Never
+ );
}
#[test]
@@ -48,6 +54,9 @@ fn parses_from_toml() {
)
.unwrap();
assert_eq!(cfg.resolve_mode("slack", "z"), VoiceReplyMode::Never);
- assert_eq!(cfg.resolve_mode("telegram", "z"), VoiceReplyMode::SpeakReply);
+ assert_eq!(
+ cfg.resolve_mode("telegram", "z"),
+ VoiceReplyMode::SpeakReply
+ );
assert_eq!(cfg.resolve_mode("telegram", "abc"), VoiceReplyMode::Always);
}
diff --git a/crates/openhuman-core/src/config/schema/mod.rs b/crates/openhuman-core/src/config/schema/mod.rs
index 6637244fd4..e7488dc1d9 100644
--- a/crates/openhuman-core/src/config/schema/mod.rs
+++ b/crates/openhuman-core/src/config/schema/mod.rs
@@ -20,8 +20,8 @@ mod cron;
mod dashboard;
mod desktop;
pub use desktop::DesktopConfig;
-mod defaults;
mod channel_voice;
+mod defaults;
mod dictation;
mod hooks;
pub use hooks::HooksConfig;
@@ -81,6 +81,7 @@ pub use agent::{
};
pub use autonomy::AutonomyConfig;
pub use capability_providers::{CapabilityProviderConfig, CapabilityProviderTrustState};
+pub use channel_voice::{ChannelVoiceConfig, ChannelVoiceOverride, VoiceReplyMode};
pub use channels::{
AuditConfig, ChannelsConfig, DingTalkConfig, DiscordConfig, EmailConfig, IMessageConfig,
IrcConfig, LarkConfig, LarkReceiveMode, LinqConfig, MatrixConfig, MattermostConfig, QQConfig,
@@ -91,7 +92,6 @@ pub(crate) use cli_overrides::set_cli_inference_overrides;
pub use context::{CompactionSettings, CompactionStrategy, ContextConfig};
pub use cron::CronConfig;
pub use dashboard::{DashboardConfig, DiagramViewerConfig, EventStreamConfig, ModelHealthConfig};
-pub use channel_voice::{ChannelVoiceConfig, ChannelVoiceOverride, VoiceReplyMode};
pub use dictation::{DictationActivationMode, DictationConfig};
pub use identity_cost::{
BudgetAction, BudgetPeriod, BudgetPolicy, BudgetScope, CostConfig, ModelPricing,