Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 37 additions & 15 deletions openless-all/app/src-tauri/src/coordinator/asr_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@

use super::*;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum CloudAsrCredentialRequirement {
AsrApiKey,
Volcengine,
}

pub(crate) fn cloud_asr_credential_requirement(
active_asr: &str,
) -> CloudAsrCredentialRequirement {
if is_whisper_compatible_provider(active_asr)
|| is_bailian_provider(active_asr)
|| is_mimo_provider(active_asr)
{
CloudAsrCredentialRequirement::AsrApiKey
} else {
CloudAsrCredentialRequirement::Volcengine
}
}

pub(crate) fn ensure_microphone_permission(_inner: &Arc<Inner>) -> Result<(), String> {
use crate::permissions::{self, PermissionStatus};

Expand Down Expand Up @@ -78,22 +97,25 @@ pub(crate) fn ensure_asr_credentials() -> Result<(), String> {
}
}

if is_whisper_compatible_provider(&active_asr) || is_bailian_provider(&active_asr) {
let api_key = CredentialsVault::get(CredentialAccount::AsrApiKey)
.ok()
.flatten()
.unwrap_or_default();
if api_key.trim().is_empty() {
return Err("请先在设置中填写 ASR 服务商 API Key".to_string());
match cloud_asr_credential_requirement(&active_asr) {
CloudAsrCredentialRequirement::AsrApiKey => {
let api_key = CredentialsVault::get(CredentialAccount::AsrApiKey)
.ok()
.flatten()
.unwrap_or_default();
if api_key.trim().is_empty() {
return Err("请先在设置中填写 ASR 服务商 API Key".to_string());
}
Ok(())
}
CloudAsrCredentialRequirement::Volcengine => {
let creds = read_volc_credentials();
if creds.app_id.trim().is_empty() || creds.access_token.trim().is_empty() {
Err("请先在设置中填写火山引擎 ASR App Key 和 Access Key".to_string())
} else {
Ok(())
}
}
return Ok(());
}

let creds = read_volc_credentials();
if creds.app_id.trim().is_empty() || creds.access_token.trim().is_empty() {
Err("请先在设置中填写火山引擎 ASR App Key 和 Access Key".to_string())
} else {
Ok(())
}
}

Expand Down
8 changes: 8 additions & 0 deletions openless-all/app/src-tauri/src/coordinator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ fn windows_local_providers_are_keyless_and_not_whisper_compatible() {
));
}

#[test]
fn credential_gate_classifies_mimo_as_api_key_asr_provider() {
assert_eq!(
cloud_asr_credential_requirement(crate::asr::mimo::PROVIDER_ID),
CloudAsrCredentialRequirement::AsrApiKey
);
}

#[test]
fn verbose_json_enabled_only_for_whisper_family() {
// verbose_json + 幻听过滤只对返回完整 Whisper 指标的 provider 开启。
Expand Down
Loading