Add a personal-account Tencent Meeting interview test bench.
The Tauri app vendors tmeet for browser OAuth, lists and creates meetings, launches the desktop client, and sends local playback audio to Doubao streaming ASR.
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
/target/
|
||||||
|
src-tauri/target/
|
||||||
|
src-tauri/gen/
|
||||||
|
*.log
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
/dist/
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
# OOKIE 腾讯会议测试台
|
||||||
|
|
||||||
|
个人版腾讯会议的面试测试应用。Tauri 2 窗口,内置官方 `tmeet` v1.1.0。
|
||||||
|
|
||||||
|
## 能做什么
|
||||||
|
|
||||||
|
- 拉起本机腾讯会议,再打开浏览器完成 OAuth。拉起客户端核对登录账号,**换不回授权**。
|
||||||
|
- 列出即将开始和进行中的会,确认后创建会议,取消前再确认一次。
|
||||||
|
- 用 `wemeet://page/inmeeting?meeting_code=` 唤起 PC/Mac 客户端入会。
|
||||||
|
- 并排看受邀人、等候室记录、参会明细。
|
||||||
|
- 把本机播放的声音送到豆包流式识别。密钥在设置页填写,进系统钥匙串。
|
||||||
|
|
||||||
|
## 做不到
|
||||||
|
|
||||||
|
- 个人版没有会中实时转写 API。字幕来自本机扬声器,不是腾讯会议的转写流。
|
||||||
|
- 没有直播在线花名册。参会明细是入会/离会记录,会还没开始时为空是正常的。
|
||||||
|
- 豆包的说话人编号对不上腾讯会议里的人名。
|
||||||
|
- 这台 Linux 构建机唤不起 Windows/Mac 客户端,也采不到会议声。
|
||||||
|
|
||||||
|
## 真机上怎么用
|
||||||
|
|
||||||
|
1. 安装并登录个人版腾讯会议。授权账号必须和客户端账号一致。
|
||||||
|
2. 打开应用,点「连接腾讯会议」,在浏览器里完成授权。
|
||||||
|
3. 设置页填豆包 API Key 和资源 ID(默认 `volc.seedasr.sauc.duration`)。保存后用「测试识别」跑 fixture。fixture 是 1.6 秒 220Hz 正弦,不是人声,只证明链路通了。
|
||||||
|
4. Windows 点「开始采集」会采默认播放设备。面试时不要放别的音频。开始前告知候选人:声音会发到豆包。
|
||||||
|
5. macOS 没有系统回环,需要先装 BlackHole 并把腾讯会议输出指过去。
|
||||||
|
|
||||||
|
## 构建
|
||||||
|
|
||||||
|
Windows 未签名 exe 用隔离的交叉构建环境,不改全局工具链:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
source /home/ubuntu/windows-cross-build/env.sh
|
||||||
|
cd /home/ubuntu/tx-meeting-test/src-tauri
|
||||||
|
unset CARGO_TARGET_DIR
|
||||||
|
cargo xwin build --release --target x86_64-pc-windows-msvc
|
||||||
|
```
|
||||||
|
|
||||||
|
产物不签名,不走发布。Linux 桌面壳在这台机器上缺少 `libdbus` 开发头文件,编不了窗口;协议库可以测:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo test -p ookie-tx-meeting-core
|
||||||
|
```
|
||||||
|
|
||||||
|
`tmeet` 二进制在 `vendor/tmeet/`,来自 npm `@tencentcloud/tmeet@1.1.0`,MIT。
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"account": "personal",
|
||||||
|
"auth": "tmeet auth login opens a browser. Launching the desktop client does not return a token.",
|
||||||
|
"liveRoster": false,
|
||||||
|
"liveTranscriptApi": false,
|
||||||
|
"transcript": "loopback of the local playback device, sent to Doubao streaming ASR",
|
||||||
|
"speakerIds": "Doubao clusters, not Tencent Meeting display names",
|
||||||
|
"events": [
|
||||||
|
"meeting.created",
|
||||||
|
"meeting.started",
|
||||||
|
"meeting.end",
|
||||||
|
"meeting.updated",
|
||||||
|
"meeting.canceled",
|
||||||
|
"recording.completed",
|
||||||
|
"smart.transcripts",
|
||||||
|
"smart.minutes"
|
||||||
|
]
|
||||||
|
}
|
||||||
Binary file not shown.
Generated
+5697
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,30 @@
|
|||||||
|
[workspace]
|
||||||
|
members = [".", "core"]
|
||||||
|
resolver = "2"
|
||||||
|
|
||||||
|
[package]
|
||||||
|
name = "ookie-tx-meeting"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
description = "Personal Tencent Meeting interview test bench"
|
||||||
|
license = "MIT"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
tauri-build = { version = "2", features = [] }
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
ookie-tx-meeting-core = { path = "core" }
|
||||||
|
tauri = { version = "2", features = [] }
|
||||||
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
serde_json = "1"
|
||||||
|
tokio = { version = "1", features = ["rt-multi-thread", "sync", "time", "macros"] }
|
||||||
|
# Linux uses the pure-Rust store so this machine can build without libdbus.
|
||||||
|
# Windows and macOS still use the OS credential store.
|
||||||
|
keyring = { version = "3", features = ["windows-native", "crypto-rust", "apple-native"] }
|
||||||
|
|
||||||
|
[target.'cfg(windows)'.dependencies]
|
||||||
|
wasapi = "=0.19.0"
|
||||||
|
|
||||||
|
[target.'cfg(not(windows))'.dependencies]
|
||||||
|
# Linux/macOS builds do not compile capture.rs's WASAPI path. The crate is
|
||||||
|
# declared so `cargo fetch` still resolves it for the Windows cross build.
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fn main() {
|
||||||
|
tauri_build::build()
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"$schema": "../gen/schemas/desktop-schema.json",
|
||||||
|
"identifier": "tx-meeting-local",
|
||||||
|
"description": "Local test window. No updater, no remote pages, no filesystem permissions.",
|
||||||
|
"windows": ["main"],
|
||||||
|
"local": true,
|
||||||
|
"permissions": ["core:default", "core:event:default"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
[package]
|
||||||
|
name = "ookie-tx-meeting-core"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
description = "tmeet runner, join URL, and Doubao ASR framing. No GUI."
|
||||||
|
license = "MIT"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
serde_json = "1"
|
||||||
|
tokio = { version = "1", features = ["rt-multi-thread", "sync", "time", "macros", "io-util", "process"] }
|
||||||
|
tokio-tungstenite = { version = "0.26", default-features = false, features = ["connect", "rustls-tls-native-roots"] }
|
||||||
|
futures-util = "0.3"
|
||||||
|
flate2 = "1"
|
||||||
|
uuid = { version = "1", features = ["v4"] }
|
||||||
@@ -0,0 +1,497 @@
|
|||||||
|
//! Doubao streaming ASR (volcengine bigmodel_async).
|
||||||
|
//!
|
||||||
|
//! Wire format is the documented 4-byte header + big-endian payload size +
|
||||||
|
//! gzip payload. Audio is pcm_s16le, 16 kHz, mono, about 200 ms per packet.
|
||||||
|
//! Speaker ids returned here are Doubao clusters. They are not Tencent Meeting names.
|
||||||
|
|
||||||
|
use crate::error::{AppError, AppResult};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use flate2::write::GzEncoder;
|
||||||
|
use flate2::read::GzDecoder;
|
||||||
|
use flate2::Compression;
|
||||||
|
use futures_util::{SinkExt, StreamExt};
|
||||||
|
use serde_json::{json, Value};
|
||||||
|
use std::io::{Read, Write};
|
||||||
|
use std::time::Duration;
|
||||||
|
use tokio::sync::mpsc;
|
||||||
|
use tokio_tungstenite::tungstenite::client::IntoClientRequest;
|
||||||
|
use tokio_tungstenite::tungstenite::http::HeaderValue;
|
||||||
|
use tokio_tungstenite::tungstenite::Message;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
pub const SAMPLE_RATE: u32 = 16_000;
|
||||||
|
|
||||||
|
/// Speech settings the GUI stores in the OS keyring. The core crate only consumes them.
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct SpeechSettings {
|
||||||
|
pub auth_mode: String,
|
||||||
|
pub api_key: String,
|
||||||
|
pub app_key: String,
|
||||||
|
pub access_key: String,
|
||||||
|
pub resource_id: String,
|
||||||
|
pub endpoint: String,
|
||||||
|
pub hotwords: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SpeechSettings {
|
||||||
|
pub fn validate(&self) -> AppResult<()> {
|
||||||
|
if !self.endpoint.starts_with("wss://") {
|
||||||
|
return Err(AppError::new("invalid_endpoint", "endpoint 必须以 wss:// 开头"));
|
||||||
|
}
|
||||||
|
if self.resource_id.trim().is_empty() {
|
||||||
|
return Err(AppError::new("invalid_resource", "资源 ID 不能为空"));
|
||||||
|
}
|
||||||
|
match self.auth_mode.as_str() {
|
||||||
|
"new" if self.api_key.trim().is_empty() => {
|
||||||
|
Err(AppError::new("credential_required", "新版控制台需要 API Key"))
|
||||||
|
}
|
||||||
|
"legacy" if self.app_key.trim().is_empty() || self.access_key.trim().is_empty() => {
|
||||||
|
Err(AppError::new("credential_required", "旧版控制台需要 App Key 和 Access Key"))
|
||||||
|
}
|
||||||
|
"new" | "legacy" => Ok(()),
|
||||||
|
_ => Err(AppError::new("invalid_auth_mode", "鉴权方式只能是 new 或 legacy")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const PACKET_MS: u32 = 200;
|
||||||
|
pub const PACKET_BYTES: usize = (SAMPLE_RATE as usize) * (PACKET_MS as usize) / 1000 * 2;
|
||||||
|
|
||||||
|
const MSG_FULL_CLIENT: u8 = 0b0001;
|
||||||
|
const MSG_AUDIO_ONLY: u8 = 0b0010;
|
||||||
|
const MSG_FULL_SERVER: u8 = 0b1001;
|
||||||
|
const MSG_ERROR: u8 = 0b1111;
|
||||||
|
|
||||||
|
const FLAG_NONE: u8 = 0b0000;
|
||||||
|
const FLAG_LAST: u8 = 0b0010;
|
||||||
|
const SERIAL_JSON: u8 = 0b0001;
|
||||||
|
const SERIAL_NONE: u8 = 0b0000;
|
||||||
|
const COMPRESS_GZIP: u8 = 0b0001;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct TranscriptEvent {
|
||||||
|
pub text: String,
|
||||||
|
pub definite: bool,
|
||||||
|
pub speaker_id: Option<String>,
|
||||||
|
pub start_ms: Option<i64>,
|
||||||
|
pub end_ms: Option<i64>,
|
||||||
|
pub log_id: Option<String>,
|
||||||
|
pub raw_error: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn hotwords(text: &str) -> Vec<Value> {
|
||||||
|
text.lines()
|
||||||
|
.map(str::trim)
|
||||||
|
.filter(|line| !line.is_empty())
|
||||||
|
.take(40)
|
||||||
|
.map(|word| json!({ "word": word }))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn header_insert(
|
||||||
|
headers: &mut tokio_tungstenite::tungstenite::http::HeaderMap,
|
||||||
|
name: &'static str,
|
||||||
|
value: &str,
|
||||||
|
label: &str,
|
||||||
|
) -> AppResult<()> {
|
||||||
|
headers.insert(
|
||||||
|
name,
|
||||||
|
HeaderValue::from_str(value).map_err(|_| {
|
||||||
|
AppError::new("invalid_credential", format!("{label} 含非法字符"))
|
||||||
|
})?,
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn gzip(bytes: &[u8]) -> AppResult<Vec<u8>> {
|
||||||
|
let mut encoder = GzEncoder::new(Vec::new(), Compression::default());
|
||||||
|
encoder
|
||||||
|
.write_all(bytes)
|
||||||
|
.map_err(|e| AppError::new("asr_frame_failed", e.to_string()))?;
|
||||||
|
encoder
|
||||||
|
.finish()
|
||||||
|
.map_err(|e| AppError::new("asr_frame_failed", e.to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn gunzip(bytes: &[u8]) -> AppResult<Vec<u8>> {
|
||||||
|
let mut decoder = GzDecoder::new(bytes);
|
||||||
|
let mut out = Vec::new();
|
||||||
|
decoder
|
||||||
|
.read_to_end(&mut out)
|
||||||
|
.map_err(|e| AppError::new("asr_frame_failed", e.to_string()))?;
|
||||||
|
Ok(out)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn header(message_type: u8, flags: u8, serialization: u8) -> [u8; 4] {
|
||||||
|
[
|
||||||
|
0b0001_0001, // version 1, header size 1 (4 bytes)
|
||||||
|
(message_type << 4) | flags,
|
||||||
|
(serialization << 4) | COMPRESS_GZIP,
|
||||||
|
0,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn frame(message_type: u8, flags: u8, serialization: u8, payload: &[u8]) -> AppResult<Vec<u8>> {
|
||||||
|
let compressed = gzip(payload)?;
|
||||||
|
let mut out = Vec::with_capacity(8 + compressed.len());
|
||||||
|
out.extend_from_slice(&header(message_type, flags, serialization));
|
||||||
|
out.extend_from_slice(&(compressed.len() as u32).to_be_bytes());
|
||||||
|
out.extend_from_slice(&compressed);
|
||||||
|
Ok(out)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn full_client_request(settings: &SpeechSettings) -> AppResult<Vec<u8>> {
|
||||||
|
let words = hotwords(&settings.hotwords);
|
||||||
|
let mut request = json!({
|
||||||
|
"model_name": "bigmodel",
|
||||||
|
"enable_itn": true,
|
||||||
|
"enable_punc": true,
|
||||||
|
"enable_ddc": false,
|
||||||
|
"show_utterances": true,
|
||||||
|
"enable_nonstream": true,
|
||||||
|
"enable_speaker_info": true,
|
||||||
|
"result_type": "full"
|
||||||
|
});
|
||||||
|
if !words.is_empty() {
|
||||||
|
request["corpus"] = json!({
|
||||||
|
"context": serde_json::to_string(&json!({ "hotwords": words })).unwrap_or_default()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let payload = json!({
|
||||||
|
"user": { "uid": "ookie-tx-meeting" },
|
||||||
|
"audio": {
|
||||||
|
"format": "pcm",
|
||||||
|
"codec": "raw",
|
||||||
|
"rate": SAMPLE_RATE,
|
||||||
|
"bits": 16,
|
||||||
|
"channel": 1
|
||||||
|
},
|
||||||
|
"request": request
|
||||||
|
});
|
||||||
|
frame(
|
||||||
|
MSG_FULL_CLIENT,
|
||||||
|
FLAG_NONE,
|
||||||
|
SERIAL_JSON,
|
||||||
|
payload.to_string().as_bytes(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn audio_frame(pcm: &[u8], last: bool) -> AppResult<Vec<u8>> {
|
||||||
|
frame(
|
||||||
|
MSG_AUDIO_ONLY,
|
||||||
|
if last { FLAG_LAST } else { FLAG_NONE },
|
||||||
|
SERIAL_NONE,
|
||||||
|
pcm,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parse one server frame. Returns None for frames that carry no transcript yet.
|
||||||
|
pub fn parse_server_frame(bytes: &[u8]) -> AppResult<Option<TranscriptEvent>> {
|
||||||
|
if bytes.len() < 8 {
|
||||||
|
return Err(AppError::new("asr_frame_failed", "响应帧过短"));
|
||||||
|
}
|
||||||
|
let message_type = bytes[1] >> 4;
|
||||||
|
let flags = bytes[1] & 0x0f;
|
||||||
|
let compression = bytes[3] & 0x0f;
|
||||||
|
let header_bytes = ((bytes[0] & 0x0f) as usize) * 4;
|
||||||
|
|
||||||
|
if message_type == MSG_ERROR {
|
||||||
|
let code = if bytes.len() >= header_bytes + 4 {
|
||||||
|
u32::from_be_bytes(bytes[header_bytes..header_bytes + 4].try_into().unwrap())
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
return Ok(Some(TranscriptEvent {
|
||||||
|
text: String::new(),
|
||||||
|
definite: true,
|
||||||
|
speaker_id: None,
|
||||||
|
start_ms: None,
|
||||||
|
end_ms: None,
|
||||||
|
log_id: None,
|
||||||
|
raw_error: Some(format!("豆包返回错误 {code}")),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
if message_type != MSG_FULL_SERVER {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut offset = header_bytes;
|
||||||
|
if flags & 0b0001 != 0 {
|
||||||
|
offset += 4; // sequence number
|
||||||
|
}
|
||||||
|
if offset + 4 > bytes.len() {
|
||||||
|
return Err(AppError::new("asr_frame_failed", "响应帧缺少长度"));
|
||||||
|
}
|
||||||
|
let size = u32::from_be_bytes(bytes[offset..offset + 4].try_into().unwrap()) as usize;
|
||||||
|
offset += 4;
|
||||||
|
if offset + size > bytes.len() {
|
||||||
|
return Err(AppError::new("asr_frame_failed", "响应帧长度不一致"));
|
||||||
|
}
|
||||||
|
let payload = &bytes[offset..offset + size];
|
||||||
|
let json_bytes = if compression == COMPRESS_GZIP {
|
||||||
|
gunzip(payload)?
|
||||||
|
} else {
|
||||||
|
payload.to_vec()
|
||||||
|
};
|
||||||
|
let value: Value = serde_json::from_slice(&json_bytes)
|
||||||
|
.map_err(|e| AppError::new("asr_frame_failed", e.to_string()))?;
|
||||||
|
Ok(event_from_payload(&value))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn event_from_payload(value: &Value) -> Option<TranscriptEvent> {
|
||||||
|
let msg = value.get("payload_msg").unwrap_or(value);
|
||||||
|
let result = msg.get("result")?;
|
||||||
|
let text = result.get("text").and_then(Value::as_str).unwrap_or("").to_string();
|
||||||
|
let log_id = result
|
||||||
|
.pointer("/additions/log_id")
|
||||||
|
.and_then(Value::as_str)
|
||||||
|
.map(str::to_string);
|
||||||
|
let utterance = result
|
||||||
|
.get("utterances")
|
||||||
|
.and_then(Value::as_array)
|
||||||
|
.and_then(|items| items.last());
|
||||||
|
let definite = utterance
|
||||||
|
.and_then(|u| u.get("definite"))
|
||||||
|
.and_then(Value::as_bool)
|
||||||
|
.unwrap_or(false);
|
||||||
|
let speaker_id = utterance
|
||||||
|
.and_then(|u| u.pointer("/additions/speaker_id"))
|
||||||
|
.and_then(Value::as_str)
|
||||||
|
.map(str::to_string);
|
||||||
|
let start_ms = utterance.and_then(|u| u.get("start_time")).and_then(Value::as_i64);
|
||||||
|
let end_ms = utterance.and_then(|u| u.get("end_time")).and_then(Value::as_i64);
|
||||||
|
if text.is_empty() && !definite {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
Some(TranscriptEvent {
|
||||||
|
text,
|
||||||
|
definite,
|
||||||
|
speaker_id,
|
||||||
|
start_ms,
|
||||||
|
end_ms,
|
||||||
|
log_id,
|
||||||
|
raw_error: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct AsrSession {
|
||||||
|
pub events: mpsc::Receiver<TranscriptEvent>,
|
||||||
|
audio: mpsc::Sender<Vec<u8>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsrSession {
|
||||||
|
pub async fn connect(settings: SpeechSettings) -> AppResult<Self> {
|
||||||
|
settings.validate()?;
|
||||||
|
let (audio_tx, audio_rx) = mpsc::channel::<Vec<u8>>(32);
|
||||||
|
let (event_tx, event_rx) = mpsc::channel::<TranscriptEvent>(64);
|
||||||
|
|
||||||
|
let request = full_client_request(&settings)?;
|
||||||
|
let url = settings.endpoint.clone();
|
||||||
|
let resource_id = settings.resource_id.clone();
|
||||||
|
let auth_mode = settings.auth_mode.clone();
|
||||||
|
let api_key = settings.api_key.clone();
|
||||||
|
let app_key = settings.app_key.clone();
|
||||||
|
let access_key = settings.access_key.clone();
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
if let Err(err) = drive(
|
||||||
|
&url,
|
||||||
|
&resource_id,
|
||||||
|
&auth_mode,
|
||||||
|
&api_key,
|
||||||
|
&app_key,
|
||||||
|
&access_key,
|
||||||
|
request,
|
||||||
|
audio_rx,
|
||||||
|
event_tx.clone(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
let _ = event_tx
|
||||||
|
.send(TranscriptEvent {
|
||||||
|
text: String::new(),
|
||||||
|
definite: true,
|
||||||
|
speaker_id: None,
|
||||||
|
start_ms: None,
|
||||||
|
end_ms: None,
|
||||||
|
log_id: None,
|
||||||
|
raw_error: Some(err.detail),
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
events: event_rx,
|
||||||
|
audio: audio_tx,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn push(&self, pcm: Vec<u8>) -> AppResult<()> {
|
||||||
|
self.audio
|
||||||
|
.send(pcm)
|
||||||
|
.await
|
||||||
|
.map_err(|_| AppError::new("asr_closed", "识别连接已关闭"))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn finish(&self) {
|
||||||
|
// Dropping the sender makes the driver send the final empty packet.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn drive(
|
||||||
|
url: &str,
|
||||||
|
resource_id: &str,
|
||||||
|
auth_mode: &str,
|
||||||
|
api_key: &str,
|
||||||
|
app_key: &str,
|
||||||
|
access_key: &str,
|
||||||
|
first: Vec<u8>,
|
||||||
|
mut audio_rx: mpsc::Receiver<Vec<u8>>,
|
||||||
|
event_tx: mpsc::Sender<TranscriptEvent>,
|
||||||
|
) -> AppResult<()> {
|
||||||
|
let mut request = url
|
||||||
|
.into_client_request()
|
||||||
|
.map_err(|e| AppError::new("asr_connect_failed", e.to_string()))?;
|
||||||
|
let headers = request.headers_mut();
|
||||||
|
header_insert(headers, "X-Api-Resource-Id", resource_id, "资源 ID")?;
|
||||||
|
header_insert(headers, "X-Api-Request-Id", &Uuid::new_v4().to_string(), "请求 ID")?;
|
||||||
|
if auth_mode == "legacy" {
|
||||||
|
header_insert(headers, "X-Api-App-Key", app_key, "App Key")?;
|
||||||
|
header_insert(headers, "X-Api-Access-Key", access_key, "Access Key")?;
|
||||||
|
} else {
|
||||||
|
header_insert(headers, "X-Api-Key", api_key, "API Key")?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let (mut socket, response) = tokio::time::timeout(
|
||||||
|
Duration::from_secs(15),
|
||||||
|
tokio_tungstenite::connect_async(request),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map_err(|_| AppError::new("asr_connect_failed", "连接豆包超时"))?
|
||||||
|
.map_err(|e| AppError::new("asr_connect_failed", e.to_string()))?;
|
||||||
|
|
||||||
|
let log_id = response
|
||||||
|
.headers()
|
||||||
|
.get("X-Tt-Logid")
|
||||||
|
.and_then(|v| v.to_str().ok())
|
||||||
|
.map(str::to_string);
|
||||||
|
|
||||||
|
socket
|
||||||
|
.send(Message::Binary(first.into()))
|
||||||
|
.await
|
||||||
|
.map_err(|e| AppError::new("asr_send_failed", e.to_string()))?;
|
||||||
|
|
||||||
|
let mut pending = Vec::new();
|
||||||
|
loop {
|
||||||
|
tokio::select! {
|
||||||
|
incoming = socket.next() => {
|
||||||
|
match incoming {
|
||||||
|
Some(Ok(Message::Binary(bytes))) => {
|
||||||
|
if let Some(mut event) = parse_server_frame(&bytes)? {
|
||||||
|
if event.log_id.is_none() {
|
||||||
|
event.log_id = log_id.clone();
|
||||||
|
}
|
||||||
|
if event.raw_error.is_some() {
|
||||||
|
let _ = event_tx.send(event).await;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
let _ = event_tx.send(event).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(Ok(Message::Close(_))) | None => break,
|
||||||
|
Some(Err(e)) => return Err(AppError::new("asr_closed", e.to_string())),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
packet = audio_rx.recv() => {
|
||||||
|
match packet {
|
||||||
|
Some(pcm) => {
|
||||||
|
pending.extend_from_slice(&pcm);
|
||||||
|
while pending.len() >= PACKET_BYTES {
|
||||||
|
let chunk: Vec<u8> = pending.drain(..PACKET_BYTES).collect();
|
||||||
|
let frame = audio_frame(&chunk, false)?;
|
||||||
|
socket.send(Message::Binary(frame.into())).await
|
||||||
|
.map_err(|e| AppError::new("asr_send_failed", e.to_string()))?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
let frame = audio_frame(&pending, true)?;
|
||||||
|
socket.send(Message::Binary(frame.into())).await
|
||||||
|
.map_err(|e| AppError::new("asr_send_failed", e.to_string()))?;
|
||||||
|
pending.clear();
|
||||||
|
// Drain a little longer so the final utterance can arrive.
|
||||||
|
let _ = tokio::time::timeout(Duration::from_secs(8), async {
|
||||||
|
while let Some(msg) = socket.next().await {
|
||||||
|
if let Ok(Message::Binary(bytes)) = msg {
|
||||||
|
if let Ok(Some(event)) = parse_server_frame(&bytes) {
|
||||||
|
let _ = event_tx.send(event).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).await;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Resample interleaved s16le PCM to 16 kHz mono with linear interpolation.
|
||||||
|
pub fn to_16k_mono(input: &[u8], channels: u16, rate: u32) -> Vec<u8> {
|
||||||
|
if input.len() < 2 || channels == 0 || rate == 0 {
|
||||||
|
return Vec::new();
|
||||||
|
}
|
||||||
|
let frame_bytes = channels as usize * 2;
|
||||||
|
let frames = input.len() / frame_bytes;
|
||||||
|
if frames == 0 {
|
||||||
|
return Vec::new();
|
||||||
|
}
|
||||||
|
let mut mono = Vec::with_capacity(frames);
|
||||||
|
for i in 0..frames {
|
||||||
|
let mut sum = 0i32;
|
||||||
|
for c in 0..channels as usize {
|
||||||
|
let off = i * frame_bytes + c * 2;
|
||||||
|
let sample = i16::from_le_bytes([input[off], input[off + 1]]) as i32;
|
||||||
|
sum += sample;
|
||||||
|
}
|
||||||
|
mono.push((sum / channels as i32) as i16);
|
||||||
|
}
|
||||||
|
if rate == SAMPLE_RATE {
|
||||||
|
return mono.iter().flat_map(|s| s.to_le_bytes()).collect();
|
||||||
|
}
|
||||||
|
let out_len = ((mono.len() as u64) * SAMPLE_RATE as u64 / rate as u64) as usize;
|
||||||
|
let mut out = Vec::with_capacity(out_len * 2);
|
||||||
|
for i in 0..out_len {
|
||||||
|
let src = (i as f64) * (rate as f64) / (SAMPLE_RATE as f64);
|
||||||
|
let idx = src.floor() as usize;
|
||||||
|
let frac = src - idx as f64;
|
||||||
|
let a = mono[idx.min(mono.len() - 1)] as f64;
|
||||||
|
let b = mono[(idx + 1).min(mono.len() - 1)] as f64;
|
||||||
|
let sample = (a + (b - a) * frac).round() as i16;
|
||||||
|
out.extend_from_slice(&sample.to_le_bytes());
|
||||||
|
}
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn resamples_stereo_48k_down_to_16k_mono() {
|
||||||
|
let mut stereo = Vec::new();
|
||||||
|
for i in 0..48u16 {
|
||||||
|
stereo.extend_from_slice(&(i as i16).to_le_bytes());
|
||||||
|
stereo.extend_from_slice(&(i as i16).to_le_bytes());
|
||||||
|
}
|
||||||
|
let out = to_16k_mono(&stereo, 2, 48_000);
|
||||||
|
assert_eq!(out.len(), 32); // 16 samples * 2 bytes
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rejects_a_short_server_frame() {
|
||||||
|
assert!(parse_server_frame(&[0, 1, 2]).is_err());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
/// Errors that cross the Tauri command boundary. The frontend only sees `code`.
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
pub struct AppError {
|
||||||
|
pub code: String,
|
||||||
|
pub detail: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AppError {
|
||||||
|
pub fn new(code: impl Into<String>, detail: impl Into<String>) -> Self {
|
||||||
|
Self {
|
||||||
|
code: code.into(),
|
||||||
|
detail: detail.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for AppError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "{}: {}", self.code, self.detail)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<AppError> for String {
|
||||||
|
fn from(value: AppError) -> Self {
|
||||||
|
serde_json::to_string(&value).unwrap_or_else(|_| value.code.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type AppResult<T> = Result<T, AppError>;
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
use crate::error::{AppError, AppResult};
|
||||||
|
use serde::Serialize;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
pub struct LaunchPlan {
|
||||||
|
pub meeting_code: String,
|
||||||
|
pub url: String,
|
||||||
|
pub command: String,
|
||||||
|
pub launched: bool,
|
||||||
|
pub note: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Personal-account join URL. This is a public client scheme, not an MCP call.
|
||||||
|
/// Windows: `cmd /C start`, macOS: `open`. Other platforms only return the URL.
|
||||||
|
pub fn client_url(meeting_code: &str) -> AppResult<String> {
|
||||||
|
let digits: String = meeting_code.chars().filter(|c| c.is_ascii_digit()).collect();
|
||||||
|
if digits.len() < 9 || digits.len() > 12 {
|
||||||
|
return Err(AppError::new(
|
||||||
|
"invalid_meeting_code",
|
||||||
|
"会议号应为 9–12 位数字",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Ok(format!("wemeet://page/inmeeting?meeting_code={digits}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn launch(meeting_code: &str) -> AppResult<LaunchPlan> {
|
||||||
|
let url = client_url(meeting_code)?;
|
||||||
|
let digits: String = meeting_code.chars().filter(|c| c.is_ascii_digit()).collect();
|
||||||
|
|
||||||
|
if cfg!(target_os = "linux") {
|
||||||
|
return Ok(LaunchPlan {
|
||||||
|
meeting_code: digits,
|
||||||
|
url: url.clone(),
|
||||||
|
command: format!("start \"\" \"{url}\""),
|
||||||
|
launched: false,
|
||||||
|
note: "当前是 Linux,无法唤起 PC/Mac 腾讯会议。把链接拿到已安装客户端的电脑上打开。".into(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut command = if cfg!(windows) {
|
||||||
|
let mut cmd = Command::new("cmd");
|
||||||
|
cmd.args(["/C", "start", "", &url]);
|
||||||
|
cmd
|
||||||
|
} else {
|
||||||
|
let mut cmd = Command::new("open");
|
||||||
|
cmd.arg(&url);
|
||||||
|
cmd
|
||||||
|
};
|
||||||
|
|
||||||
|
match command.spawn() {
|
||||||
|
Ok(child) => {
|
||||||
|
drop(child);
|
||||||
|
Ok(LaunchPlan {
|
||||||
|
meeting_code: digits,
|
||||||
|
url,
|
||||||
|
command: if cfg!(windows) {
|
||||||
|
"cmd /C start".into()
|
||||||
|
} else {
|
||||||
|
"open".into()
|
||||||
|
},
|
||||||
|
launched: true,
|
||||||
|
note: "已请求系统打开腾讯会议。若客户端未安装或未登录,这次唤起不会入会。".into(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Err(e) => Err(AppError::new("launch_failed", e.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Bring the installed client to the front before OAuth, so the user can confirm
|
||||||
|
/// the personal account. Failure here is not fatal: auth still happens in the browser.
|
||||||
|
pub fn focus_client() -> AppResult<String> {
|
||||||
|
if cfg!(target_os = "linux") {
|
||||||
|
return Ok("Linux 上无法拉起腾讯会议客户端。授权仍在浏览器完成。".into());
|
||||||
|
}
|
||||||
|
let url = "wemeet://page/home";
|
||||||
|
let result = if cfg!(windows) {
|
||||||
|
Command::new("cmd").args(["/C", "start", "", url]).spawn()
|
||||||
|
} else {
|
||||||
|
Command::new("open").arg(url).spawn()
|
||||||
|
};
|
||||||
|
match result {
|
||||||
|
Ok(child) => {
|
||||||
|
drop(child);
|
||||||
|
Ok("已尝试拉起腾讯会议。请确认客户端登录的是个人账号,再回浏览器完成授权。".into())
|
||||||
|
}
|
||||||
|
Err(e) => Ok(format!("拉起客户端失败({e})。可直接在浏览器完成授权。")),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
pub mod asr;
|
||||||
|
pub mod error;
|
||||||
|
pub mod launch;
|
||||||
|
pub mod tmeet;
|
||||||
|
|
||||||
|
pub use error::{AppError, AppResult};
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::tmeet::not_logged_in;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn logged_out_text_is_not_a_session() {
|
||||||
|
assert!(not_logged_in(
|
||||||
|
"Not logged in. Please use 'tmeet auth login' to authenticate.\n",
|
||||||
|
""
|
||||||
|
));
|
||||||
|
assert!(not_logged_in(
|
||||||
|
"",
|
||||||
|
"Error: user config is empty, please use 'tmeet auth login'"
|
||||||
|
));
|
||||||
|
assert!(!not_logged_in(r#"{"open_id":"abc"}"#, ""));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,182 @@
|
|||||||
|
use crate::error::{AppError, AppResult};
|
||||||
|
use serde_json::Value;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::process::Stdio;
|
||||||
|
use std::time::Duration;
|
||||||
|
use tokio::io::{AsyncRead, AsyncReadExt};
|
||||||
|
use tokio::process::Command;
|
||||||
|
|
||||||
|
const MAX_OUTPUT: usize = 4 * 1024 * 1024;
|
||||||
|
|
||||||
|
/// Locate the vendored tmeet binary.
|
||||||
|
///
|
||||||
|
/// Dev: `vendor/tmeet/<platform>/tmeet[.exe]`, walked up from the executable
|
||||||
|
/// and from the current directory.
|
||||||
|
/// Packaged: `tmeet[.exe]` beside the application executable.
|
||||||
|
pub fn locate() -> AppResult<PathBuf> {
|
||||||
|
let exe_name = if cfg!(windows) { "tmeet.exe" } else { "tmeet" };
|
||||||
|
let platform_dir = platform_dir();
|
||||||
|
|
||||||
|
let mut candidates = Vec::new();
|
||||||
|
if let Ok(exe) = std::env::current_exe() {
|
||||||
|
if let Some(dir) = exe.parent() {
|
||||||
|
candidates.push(dir.join(exe_name));
|
||||||
|
candidates.push(dir.join("vendor").join("tmeet").join(platform_dir).join(exe_name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Ok(cwd) = std::env::current_dir() {
|
||||||
|
candidates.push(cwd.join("vendor").join("tmeet").join(platform_dir).join(exe_name));
|
||||||
|
let mut cursor = cwd.as_path();
|
||||||
|
for _ in 0..4 {
|
||||||
|
candidates.push(cursor.join("vendor").join("tmeet").join(platform_dir).join(exe_name));
|
||||||
|
match cursor.parent() {
|
||||||
|
Some(parent) => cursor = parent,
|
||||||
|
None => break,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
candidates
|
||||||
|
.into_iter()
|
||||||
|
.find(|path| path.is_file())
|
||||||
|
.ok_or_else(|| {
|
||||||
|
AppError::new(
|
||||||
|
"tmeet_missing",
|
||||||
|
"找不到内置的 tmeet。开发时它应在 vendor/tmeet/<平台>/ 下。",
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn platform_dir() -> &'static str {
|
||||||
|
if cfg!(windows) {
|
||||||
|
"windows-x86_64"
|
||||||
|
} else if cfg!(target_os = "macos") {
|
||||||
|
if cfg!(target_arch = "aarch64") {
|
||||||
|
"macos-aarch64"
|
||||||
|
} else {
|
||||||
|
"macos-x86_64"
|
||||||
|
}
|
||||||
|
} else if cfg!(target_arch = "aarch64") {
|
||||||
|
"linux-aarch64"
|
||||||
|
} else {
|
||||||
|
"linux-x86_64"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct TmeetOutput {
|
||||||
|
pub status: i32,
|
||||||
|
pub stdout: String,
|
||||||
|
pub stderr: String,
|
||||||
|
pub json: Option<Value>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Run tmeet. `timeout` bounds the call; login uses a longer one because it
|
||||||
|
/// waits for the browser OAuth round-trip (the CLI itself times out at 5 min).
|
||||||
|
pub async fn run(args: &[&str], timeout: Duration) -> AppResult<TmeetOutput> {
|
||||||
|
let bin = locate()?;
|
||||||
|
run_at(&bin, args, timeout).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn run_at(bin: &Path, args: &[&str], timeout: Duration) -> AppResult<TmeetOutput> {
|
||||||
|
let mut command = Command::new(bin);
|
||||||
|
command
|
||||||
|
.args(args)
|
||||||
|
.stdin(Stdio::null())
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.stderr(Stdio::piped())
|
||||||
|
.kill_on_drop(true);
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
command.creation_flags(0x08000000); // CREATE_NO_WINDOW
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut child = command
|
||||||
|
.spawn()
|
||||||
|
.map_err(|e| AppError::new("tmeet_spawn_failed", e.to_string()))?;
|
||||||
|
|
||||||
|
let mut stdout = child.stdout.take().ok_or_else(|| {
|
||||||
|
AppError::new("tmeet_spawn_failed", "无法读取 tmeet 标准输出")
|
||||||
|
})?;
|
||||||
|
let mut stderr = child.stderr.take().ok_or_else(|| {
|
||||||
|
AppError::new("tmeet_spawn_failed", "无法读取 tmeet 标准错误")
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let stdout_task = tokio::spawn(async move { read_capped(&mut stdout).await });
|
||||||
|
let stderr_task = tokio::spawn(async move { read_capped(&mut stderr).await });
|
||||||
|
|
||||||
|
let status = tokio::time::timeout(timeout, child.wait())
|
||||||
|
.await
|
||||||
|
.map_err(|_| AppError::new("tmeet_timeout", "tmeet 超时未返回"))?
|
||||||
|
.map_err(|e| AppError::new("tmeet_failed", e.to_string()))?;
|
||||||
|
|
||||||
|
let stdout = stdout_task
|
||||||
|
.await
|
||||||
|
.map_err(|e| AppError::new("tmeet_failed", e.to_string()))??;
|
||||||
|
let stderr = stderr_task
|
||||||
|
.await
|
||||||
|
.map_err(|e| AppError::new("tmeet_failed", e.to_string()))??;
|
||||||
|
|
||||||
|
let json = parse_json(&stdout);
|
||||||
|
Ok(TmeetOutput {
|
||||||
|
status: status.code().unwrap_or(-1),
|
||||||
|
stdout,
|
||||||
|
stderr,
|
||||||
|
json,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn read_capped(reader: &mut (impl AsyncRead + Unpin)) -> AppResult<String> {
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
let mut chunk = [0u8; 8192];
|
||||||
|
loop {
|
||||||
|
let n = reader
|
||||||
|
.read(&mut chunk)
|
||||||
|
.await
|
||||||
|
.map_err(|e| AppError::new("tmeet_failed", e.to_string()))?;
|
||||||
|
if n == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if buf.len() + n > MAX_OUTPUT {
|
||||||
|
return Err(AppError::new("tmeet_output_limit", "tmeet 输出超过 4MB"));
|
||||||
|
}
|
||||||
|
buf.extend_from_slice(&chunk[..n]);
|
||||||
|
}
|
||||||
|
Ok(String::from_utf8_lossy(&buf).into_owned())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn not_logged_in(stdout: &str, stderr: &str) -> bool {
|
||||||
|
let blob = format!("{stdout}\n{stderr}").to_ascii_lowercase();
|
||||||
|
blob.contains("not logged in") || blob.contains("user config is empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_json(stdout: &str) -> Option<Value> {
|
||||||
|
let trimmed = stdout.trim();
|
||||||
|
if trimmed.is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
serde_json::from_str(trimmed).ok().or_else(|| {
|
||||||
|
// Some commands print a hint after the JSON array. Take the first JSON value.
|
||||||
|
let start = trimmed.find(['{', '['])?;
|
||||||
|
let slice = &trimmed[start..];
|
||||||
|
serde_json::from_str(slice).ok()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn require_ok(output: TmeetOutput) -> AppResult<TmeetOutput> {
|
||||||
|
if output.status != 0 {
|
||||||
|
let detail = if !output.stderr.trim().is_empty() {
|
||||||
|
output.stderr.trim().to_string()
|
||||||
|
} else {
|
||||||
|
output.stdout.trim().to_string()
|
||||||
|
};
|
||||||
|
return Err(AppError::new(
|
||||||
|
"tmeet_failed",
|
||||||
|
if detail.is_empty() {
|
||||||
|
format!("tmeet 退出码 {}", output.status)
|
||||||
|
} else {
|
||||||
|
detail
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Ok(output)
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 90 KiB |
@@ -0,0 +1,150 @@
|
|||||||
|
//! Loopback capture of the default playback device.
|
||||||
|
//!
|
||||||
|
//! Windows uses WASAPI loopback: open the render endpoint, then initialize a
|
||||||
|
//! capture client on it. That is "what you hear", not a single process.
|
||||||
|
//! macOS has no system loopback. Linux has no Tencent Meeting client to capture.
|
||||||
|
|
||||||
|
use ookie_tx_meeting_core::asr::{to_16k_mono, AsrSession, SAMPLE_RATE};
|
||||||
|
use ookie_tx_meeting_core::error::{AppError, AppResult};
|
||||||
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
|
pub fn platform_note() -> &'static str {
|
||||||
|
if cfg!(windows) {
|
||||||
|
"Windows:采集默认播放设备。腾讯会议的声音和其他正在播放的声音都会进去。面试时不要放别的音频。"
|
||||||
|
} else if cfg!(target_os = "macos") {
|
||||||
|
"macOS 没有系统回环。请先安装 BlackHole,把腾讯会议的输出指到它。本原型不假装能直接采。"
|
||||||
|
} else {
|
||||||
|
"当前是 Linux,没有可采集的腾讯会议播放输出。用「测试识别」跑 fixture,或在 Windows 真机上采集。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn capture_to(session: AsrSession, stop: mpsc::Receiver<()>) -> AppResult<()> {
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
capture_wasapi(session, stop).await
|
||||||
|
}
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
{
|
||||||
|
let _ = (session, stop);
|
||||||
|
Err(AppError::new("capture_unavailable", platform_note()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
async fn capture_wasapi(session: AsrSession, mut stop: mpsc::Receiver<()>) -> AppResult<()> {
|
||||||
|
let (tx, mut rx) = mpsc::channel::<Vec<u8>>(16);
|
||||||
|
let (ready_tx, ready_rx) = tokio::sync::oneshot::channel::<Result<(), String>>();
|
||||||
|
|
||||||
|
std::thread::spawn(move || {
|
||||||
|
let result = wasapi_thread(tx);
|
||||||
|
let _ = ready_tx.send(result);
|
||||||
|
});
|
||||||
|
|
||||||
|
match ready_rx.await {
|
||||||
|
Ok(Ok(())) => {}
|
||||||
|
Ok(Err(detail)) => return Err(AppError::new("capture_failed", detail)),
|
||||||
|
Err(_) => return Err(AppError::new("capture_failed", "采集线程退出")),
|
||||||
|
}
|
||||||
|
|
||||||
|
loop {
|
||||||
|
tokio::select! {
|
||||||
|
packet = rx.recv() => {
|
||||||
|
match packet {
|
||||||
|
Some(pcm) => session.push(pcm).await?,
|
||||||
|
None => break,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ = stop.recv() => break,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn wasapi_thread(tx: mpsc::Sender<Vec<u8>>) -> Result<(), String> {
|
||||||
|
use wasapi::{DeviceCollection, Direction, SampleType, StreamMode, WaveFormat};
|
||||||
|
|
||||||
|
let hr = wasapi::initialize_mta();
|
||||||
|
if hr.is_err() {
|
||||||
|
return Err(format!("COM 初始化失败: {hr:?}"));
|
||||||
|
}
|
||||||
|
// 0.19 has no DeviceEnumerator. The first active render device is the default output.
|
||||||
|
let collection = DeviceCollection::new(&Direction::Render).map_err(|e| e.to_string())?;
|
||||||
|
let device = collection
|
||||||
|
.get_device_at_index(0)
|
||||||
|
.map_err(|e| format!("找不到播放设备: {e}"))?;
|
||||||
|
let mut audio_client = device.get_iaudioclient().map_err(|e| format!("无法打开播放设备: {e}"))?;
|
||||||
|
let mix = audio_client.get_mixformat().map_err(|e| format!("无法读取混音格式: {e}"))?;
|
||||||
|
let channels = mix.get_nchannels();
|
||||||
|
let rate = mix.get_samplespersec();
|
||||||
|
let sample_type = mix.get_subformat().map_err(|e| format!("无法识别采样格式: {e}"))?;
|
||||||
|
let desired = WaveFormat::new(
|
||||||
|
mix.get_bitspersample() as usize,
|
||||||
|
mix.get_validbitspersample() as usize,
|
||||||
|
&sample_type,
|
||||||
|
rate as usize,
|
||||||
|
channels as usize,
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
let (default_period, _) = audio_client.get_device_period().map_err(|e| e.to_string())?;
|
||||||
|
let mode = StreamMode::EventsShared {
|
||||||
|
autoconvert: true,
|
||||||
|
buffer_duration_hns: default_period.max(200_000),
|
||||||
|
};
|
||||||
|
audio_client
|
||||||
|
.initialize_client(&desired, &Direction::Capture, &mode)
|
||||||
|
.map_err(|e| format!("初始化回环失败: {e}"))?;
|
||||||
|
let capture = audio_client.get_audiocaptureclient().map_err(|e| e.to_string())?;
|
||||||
|
let event = audio_client.set_get_eventhandle().map_err(|e| e.to_string())?;
|
||||||
|
audio_client.start_stream().map_err(|e| format!("无法开始采集: {e}"))?;
|
||||||
|
|
||||||
|
let mut acc = Vec::new();
|
||||||
|
let mut scratch = vec![0u8; 64 * 1024];
|
||||||
|
loop {
|
||||||
|
if tx.is_closed() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if event.wait_for_event(500).is_err() {
|
||||||
|
if tx.is_closed() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let (frames, _) = match capture.read_from_device(&mut scratch) {
|
||||||
|
Ok(read) => read,
|
||||||
|
Err(_) => break,
|
||||||
|
};
|
||||||
|
let byte_count = frames as usize * mix.get_blockalign() as usize;
|
||||||
|
if frames == 0 || byte_count == 0 || byte_count > scratch.len() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let chunk = &scratch[..byte_count];
|
||||||
|
let pcm = if sample_type == SampleType::Float {
|
||||||
|
f32_bytes_to_s16(chunk, channels, rate)
|
||||||
|
} else {
|
||||||
|
to_16k_mono(chunk, channels, rate)
|
||||||
|
};
|
||||||
|
acc.extend_from_slice(&pcm);
|
||||||
|
let packet = (SAMPLE_RATE as usize) * 2 / 5; // 200 ms
|
||||||
|
while acc.len() >= packet {
|
||||||
|
let send: Vec<u8> = acc.drain(..packet).collect();
|
||||||
|
if tx.blocking_send(send).is_err() {
|
||||||
|
let _ = audio_client.stop_stream();
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let _ = audio_client.stop_stream();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn f32_bytes_to_s16(input: &[u8], channels: u16, rate: u32) -> Vec<u8> {
|
||||||
|
let mut s16 = Vec::with_capacity(input.len() / 2);
|
||||||
|
for frame in input.chunks_exact(4) {
|
||||||
|
let sample = f32::from_le_bytes([frame[0], frame[1], frame[2], frame[3]]);
|
||||||
|
let clipped = (sample.clamp(-1.0, 1.0) * i16::MAX as f32) as i16;
|
||||||
|
s16.extend_from_slice(&clipped.to_le_bytes());
|
||||||
|
}
|
||||||
|
to_16k_mono(&s16, channels, rate)
|
||||||
|
}
|
||||||
@@ -0,0 +1,372 @@
|
|||||||
|
use crate::capture;
|
||||||
|
use crate::settings;
|
||||||
|
use ookie_tx_meeting_core::asr::SpeechSettings;
|
||||||
|
use ookie_tx_meeting_core::asr::{AsrSession, TranscriptEvent};
|
||||||
|
use ookie_tx_meeting_core::error::{AppError, AppResult};
|
||||||
|
use ookie_tx_meeting_core::launch;
|
||||||
|
use ookie_tx_meeting_core::tmeet;
|
||||||
|
use serde::Serialize;
|
||||||
|
use serde_json::{json, Value};
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
use std::time::Duration;
|
||||||
|
use tauri::{AppHandle, Emitter, State};
|
||||||
|
use tokio::sync::{mpsc, Mutex};
|
||||||
|
|
||||||
|
pub struct AppState {
|
||||||
|
pub capturing: AtomicBool,
|
||||||
|
stop_capture: Mutex<Option<mpsc::Sender<()>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for AppState {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
capturing: AtomicBool::new(false),
|
||||||
|
stop_capture: Mutex::new(None),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn emit_transcript(app: &AppHandle, event: &TranscriptEvent, source: &str) {
|
||||||
|
let _ = app.emit(
|
||||||
|
"transcript",
|
||||||
|
json!({
|
||||||
|
"source": source,
|
||||||
|
"text": event.text,
|
||||||
|
"definite": event.definite,
|
||||||
|
"speakerId": event.speaker_id,
|
||||||
|
"startMs": event.start_ms,
|
||||||
|
"endMs": event.end_ms,
|
||||||
|
"logId": event.log_id,
|
||||||
|
"error": event.raw_error,
|
||||||
|
"speakerNote": "豆包的说话人编号不是腾讯会议里的人名"
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn forward_events(app: AppHandle, mut events: mpsc::Receiver<TranscriptEvent>, source: String) {
|
||||||
|
while let Some(event) = events.recv().await {
|
||||||
|
emit_transcript(&app, &event, &source);
|
||||||
|
}
|
||||||
|
let _ = app.emit("transcript-closed", json!({ "source": source }));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct AuthView {
|
||||||
|
pub logged_in: bool,
|
||||||
|
pub summary: String,
|
||||||
|
pub raw: Value,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn app_info() -> Value {
|
||||||
|
json!({
|
||||||
|
"name": "OOKIE 腾讯会议测试台",
|
||||||
|
"account": "个人版",
|
||||||
|
"limits": [
|
||||||
|
"个人版没有会中实时转写 API,字幕来自本机播放声音 + 豆包",
|
||||||
|
"个人版没有直播在线花名册,会中只能看到受邀人和等候室记录",
|
||||||
|
"豆包说话人编号对不上腾讯会议人名",
|
||||||
|
"授权在浏览器完成,拉起客户端只用来核对登录账号"
|
||||||
|
],
|
||||||
|
"capture": capture::platform_note()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn tmeet_status() -> AppResult<AuthView> {
|
||||||
|
let output = tmeet::run(&["--format", "json", "auth", "status"], Duration::from_secs(20)).await?;
|
||||||
|
// v1.1.0 prints "Not logged in" and still exits 0. Do not trust the exit code alone.
|
||||||
|
let logged_in = output.status == 0 && !tmeet::not_logged_in(&output.stdout, &output.stderr);
|
||||||
|
Ok(AuthView {
|
||||||
|
logged_in,
|
||||||
|
summary: if logged_in {
|
||||||
|
"已登录".into()
|
||||||
|
} else {
|
||||||
|
"未登录".into()
|
||||||
|
},
|
||||||
|
raw: output.json.unwrap_or(json!({ "stdout": output.stdout, "stderr": output.stderr })),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn tmeet_login() -> AppResult<Value> {
|
||||||
|
let focus = launch::focus_client()?;
|
||||||
|
// The CLI blocks until the browser flow finishes or its own 5-minute timer fires.
|
||||||
|
let output = tmeet::run(
|
||||||
|
&["--format", "json", "auth", "login"],
|
||||||
|
Duration::from_secs(330),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
if output.status != 0 {
|
||||||
|
return Err(AppError::new(
|
||||||
|
"login_failed",
|
||||||
|
format!(
|
||||||
|
"{}\n{}",
|
||||||
|
output.stderr.trim(),
|
||||||
|
output.stdout.trim()
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Ok(json!({
|
||||||
|
"focus": focus,
|
||||||
|
"stdout": output.stdout,
|
||||||
|
"stderr": output.stderr
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn tmeet_logout() -> AppResult<Value> {
|
||||||
|
let output = tmeet::require_ok(
|
||||||
|
tmeet::run(&["--format", "json", "auth", "logout"], Duration::from_secs(30)).await?,
|
||||||
|
)?;
|
||||||
|
Ok(output.json.unwrap_or(json!({ "stdout": output.stdout })))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn meeting_list() -> AppResult<Value> {
|
||||||
|
let output = tmeet::require_ok(
|
||||||
|
tmeet::run(
|
||||||
|
&["--format", "json", "meeting", "list", "--page-size", "20"],
|
||||||
|
Duration::from_secs(30),
|
||||||
|
)
|
||||||
|
.await?,
|
||||||
|
)?;
|
||||||
|
Ok(output.json.unwrap_or(json!({ "stdout": output.stdout })))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn meeting_create(subject: String, start: String, end: String) -> AppResult<Value> {
|
||||||
|
if subject.trim().is_empty() || subject.chars().count() > 80 {
|
||||||
|
return Err(AppError::new("invalid_subject", "主题不能为空,且不超过 80 字"));
|
||||||
|
}
|
||||||
|
if !looks_like_iso(&start) || !looks_like_iso(&end) {
|
||||||
|
return Err(AppError::new(
|
||||||
|
"invalid_time",
|
||||||
|
"时间用 ISO 8601,例如 2026-11-14T15:00:00+08:00",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let output = tmeet::require_ok(
|
||||||
|
tmeet::run(
|
||||||
|
&[
|
||||||
|
"--format",
|
||||||
|
"json",
|
||||||
|
"meeting",
|
||||||
|
"create",
|
||||||
|
"--subject",
|
||||||
|
subject.trim(),
|
||||||
|
"--start",
|
||||||
|
start.trim(),
|
||||||
|
"--end",
|
||||||
|
end.trim(),
|
||||||
|
],
|
||||||
|
Duration::from_secs(40),
|
||||||
|
)
|
||||||
|
.await?,
|
||||||
|
)?;
|
||||||
|
Ok(output.json.unwrap_or(json!({ "stdout": output.stdout })))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn looks_like_iso(value: &str) -> bool {
|
||||||
|
let v = value.trim();
|
||||||
|
v.len() >= 16 && v.len() <= 40 && v.contains('T') && !v.contains(['\n', '\r', '"'])
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn meeting_get(meeting_code: String) -> AppResult<Value> {
|
||||||
|
let code = digits(&meeting_code)?;
|
||||||
|
let output = tmeet::require_ok(
|
||||||
|
tmeet::run(
|
||||||
|
&["--format", "json", "meeting", "get", "--meeting-code", &code],
|
||||||
|
Duration::from_secs(30),
|
||||||
|
)
|
||||||
|
.await?,
|
||||||
|
)?;
|
||||||
|
Ok(output.json.unwrap_or(json!({ "stdout": output.stdout })))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn meeting_cancel(meeting_id: String) -> AppResult<Value> {
|
||||||
|
let id = meeting_id.trim();
|
||||||
|
if id.is_empty() || id.len() > 64 || id.contains([' ', '\n', '"']) {
|
||||||
|
return Err(AppError::new("invalid_meeting_id", "会议 ID 不合法"));
|
||||||
|
}
|
||||||
|
let output = tmeet::require_ok(
|
||||||
|
tmeet::run(
|
||||||
|
&["--format", "json", "meeting", "cancel", "--meeting-id", id],
|
||||||
|
Duration::from_secs(30),
|
||||||
|
)
|
||||||
|
.await?,
|
||||||
|
)?;
|
||||||
|
Ok(output.json.unwrap_or(json!({ "stdout": output.stdout })))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn meeting_launch(meeting_code: String) -> AppResult<launch::LaunchPlan> {
|
||||||
|
launch::launch(&meeting_code)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn meeting_people(meeting_id: String) -> AppResult<Value> {
|
||||||
|
let id = meeting_id.trim();
|
||||||
|
if id.is_empty() || id.len() > 64 || id.contains([' ', '\n', '"']) {
|
||||||
|
return Err(AppError::new("invalid_meeting_id", "会议 ID 不合法"));
|
||||||
|
}
|
||||||
|
let invitees = tmeet::run(
|
||||||
|
&[
|
||||||
|
"--format",
|
||||||
|
"json",
|
||||||
|
"meeting",
|
||||||
|
"invitees-list",
|
||||||
|
"--meeting-id",
|
||||||
|
id,
|
||||||
|
],
|
||||||
|
Duration::from_secs(30),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
let participants = tmeet::run(
|
||||||
|
&[
|
||||||
|
"--format",
|
||||||
|
"json",
|
||||||
|
"report",
|
||||||
|
"participants",
|
||||||
|
"--meeting-id",
|
||||||
|
id,
|
||||||
|
],
|
||||||
|
Duration::from_secs(30),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
let waiting = tmeet::run(
|
||||||
|
&[
|
||||||
|
"--format",
|
||||||
|
"json",
|
||||||
|
"report",
|
||||||
|
"waiting-room-log",
|
||||||
|
"--meeting-id",
|
||||||
|
id,
|
||||||
|
],
|
||||||
|
Duration::from_secs(30),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
Ok(json!({
|
||||||
|
"invitees": invitees.json.unwrap_or(json!({ "stdout": invitees.stdout, "stderr": invitees.stderr, "status": invitees.status })),
|
||||||
|
"participants": participants.json.unwrap_or(json!({ "stdout": participants.stdout, "stderr": participants.stderr, "status": participants.status })),
|
||||||
|
"waitingRoom": waiting.json.unwrap_or(json!({ "stdout": waiting.stdout, "stderr": waiting.stderr, "status": waiting.status })),
|
||||||
|
"note": "参会明细是入会/离会记录,不是直播在线花名册。会还没开始时为空是正常的。"
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn digits(value: &str) -> AppResult<String> {
|
||||||
|
let code: String = value.chars().filter(|c| c.is_ascii_digit()).collect();
|
||||||
|
if code.len() < 9 || code.len() > 12 {
|
||||||
|
return Err(AppError::new("invalid_meeting_code", "会议号应为 9–12 位数字"));
|
||||||
|
}
|
||||||
|
Ok(code)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn speech_get() -> Value {
|
||||||
|
serde_json::to_value(settings::view(&settings::load())).unwrap_or(json!({}))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn speech_save(incoming: SpeechSettings) -> AppResult<Value> {
|
||||||
|
let previous = settings::load();
|
||||||
|
let next = settings::merge_secrets(incoming, &previous);
|
||||||
|
settings::save(&next)?;
|
||||||
|
Ok(serde_json::to_value(settings::view(&next)).unwrap_or(json!({})))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn speech_test(app: AppHandle) -> AppResult<Value> {
|
||||||
|
let settings = settings::load();
|
||||||
|
settings.validate()?;
|
||||||
|
let pcm = fixture_pcm()?;
|
||||||
|
let mut session = AsrSession::connect(settings).await?;
|
||||||
|
let events = std::mem::replace(&mut session.events, mpsc::channel(1).1);
|
||||||
|
tokio::spawn(forward_events(app, events, "fixture".into()));
|
||||||
|
session.push(pcm).await?;
|
||||||
|
session.finish();
|
||||||
|
Ok(json!({
|
||||||
|
"started": true,
|
||||||
|
"note": "fixture 是 1.6 秒 220Hz 正弦,不是人声。豆包可能返回空或无意义文本,这只证明链路通了。"
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fixture_pcm() -> AppResult<Vec<u8>> {
|
||||||
|
let path = fixture_path()?;
|
||||||
|
let bytes = std::fs::read(&path)
|
||||||
|
.map_err(|e| AppError::new("fixture_missing", format!("{}: {e}", path.display())))?;
|
||||||
|
// Standard 44-byte PCM WAV header. The fixture is written that way.
|
||||||
|
if bytes.len() < 44 || &bytes[0..4] != b"RIFF" {
|
||||||
|
return Err(AppError::new("fixture_invalid", "fixture 不是 WAV"));
|
||||||
|
}
|
||||||
|
Ok(bytes[44..].to_vec())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fixture_path() -> AppResult<std::path::PathBuf> {
|
||||||
|
let mut candidates = Vec::new();
|
||||||
|
if let Ok(cwd) = std::env::current_dir() {
|
||||||
|
candidates.push(cwd.join("fixtures").join("sample.wav"));
|
||||||
|
if let Some(parent) = cwd.parent() {
|
||||||
|
candidates.push(parent.join("fixtures").join("sample.wav"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Ok(exe) = std::env::current_exe() {
|
||||||
|
if let Some(dir) = exe.parent() {
|
||||||
|
candidates.push(dir.join("fixtures").join("sample.wav"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
candidates
|
||||||
|
.into_iter()
|
||||||
|
.find(|path| path.is_file())
|
||||||
|
.ok_or_else(|| AppError::new("fixture_missing", "找不到 fixtures/sample.wav"))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn capture_start(app: AppHandle, state: State<'_, AppState>) -> AppResult<Value> {
|
||||||
|
if state.capturing.swap(true, Ordering::SeqCst) {
|
||||||
|
return Err(AppError::new("already_capturing", "已经在采集"));
|
||||||
|
}
|
||||||
|
let started = capture_start_inner(app, &state).await;
|
||||||
|
if started.is_err() {
|
||||||
|
state.capturing.store(false, Ordering::SeqCst);
|
||||||
|
}
|
||||||
|
started
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn capture_start_inner(app: AppHandle, state: &AppState) -> AppResult<Value> {
|
||||||
|
let settings = settings::load();
|
||||||
|
settings.validate()?;
|
||||||
|
let session = AsrSession::connect(settings).await?;
|
||||||
|
let (stop_tx, stop_rx) = mpsc::channel(1);
|
||||||
|
*state.stop_capture.lock().await = Some(stop_tx);
|
||||||
|
let mut session = session;
|
||||||
|
let events = std::mem::replace(&mut session.events, mpsc::channel(1).1);
|
||||||
|
let app_for_task = app.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
if let Err(err) = capture::capture_to(session, stop_rx).await {
|
||||||
|
let _ = app_for_task.emit(
|
||||||
|
"transcript",
|
||||||
|
json!({ "source": "loopback", "error": err.detail, "text": "", "definite": true }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let app2 = app.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
forward_events(app2, events, "loopback".into()).await;
|
||||||
|
});
|
||||||
|
Ok(json!({
|
||||||
|
"started": true,
|
||||||
|
"note": capture::platform_note(),
|
||||||
|
"privacy": "候选人的声音会发到你在设置里填写的豆包服务。开始前需要已告知对方。"
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn capture_stop(state: State<'_, AppState>) -> AppResult<Value> {
|
||||||
|
state.capturing.store(false, Ordering::SeqCst);
|
||||||
|
if let Some(stop) = state.stop_capture.lock().await.take() {
|
||||||
|
let _ = stop.send(()).await;
|
||||||
|
}
|
||||||
|
Ok(json!({ "stopped": true }))
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
|
mod capture;
|
||||||
|
mod commands;
|
||||||
|
mod settings;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
tauri::Builder::default()
|
||||||
|
.manage(commands::AppState::default())
|
||||||
|
.invoke_handler(tauri::generate_handler![
|
||||||
|
commands::app_info,
|
||||||
|
commands::tmeet_status,
|
||||||
|
commands::tmeet_login,
|
||||||
|
commands::tmeet_logout,
|
||||||
|
commands::meeting_list,
|
||||||
|
commands::meeting_create,
|
||||||
|
commands::meeting_get,
|
||||||
|
commands::meeting_cancel,
|
||||||
|
commands::meeting_launch,
|
||||||
|
commands::meeting_people,
|
||||||
|
commands::speech_get,
|
||||||
|
commands::speech_save,
|
||||||
|
commands::speech_test,
|
||||||
|
commands::capture_start,
|
||||||
|
commands::capture_stop,
|
||||||
|
])
|
||||||
|
.run(tauri::generate_context!())
|
||||||
|
.expect("腾讯会议测试台启动失败");
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
use ookie_tx_meeting_core::asr::SpeechSettings;
|
||||||
|
use ookie_tx_meeting_core::error::{AppError, AppResult};
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
pub const KEYRING_SERVICE: &str = "school.oops.ookie.tx-meeting";
|
||||||
|
const KEYRING_USER: &str = "doubao-asr";
|
||||||
|
|
||||||
|
pub fn default_settings() -> SpeechSettings {
|
||||||
|
SpeechSettings {
|
||||||
|
auth_mode: "new".into(),
|
||||||
|
api_key: String::new(),
|
||||||
|
app_key: String::new(),
|
||||||
|
access_key: String::new(),
|
||||||
|
resource_id: "volc.seedasr.sauc.duration".into(),
|
||||||
|
endpoint: "wss://openspeech.bytedance.com/api/v3/sauc/bigmodel_async".into(),
|
||||||
|
hotwords: String::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct SpeechSettingsView {
|
||||||
|
pub auth_mode: String,
|
||||||
|
pub api_key_set: bool,
|
||||||
|
pub api_key_hint: String,
|
||||||
|
pub app_key: String,
|
||||||
|
pub access_key_set: bool,
|
||||||
|
pub access_key_hint: String,
|
||||||
|
pub resource_id: String,
|
||||||
|
pub endpoint: String,
|
||||||
|
pub hotwords: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn view(settings: &SpeechSettings) -> SpeechSettingsView {
|
||||||
|
SpeechSettingsView {
|
||||||
|
auth_mode: settings.auth_mode.clone(),
|
||||||
|
api_key_set: !settings.api_key.is_empty(),
|
||||||
|
api_key_hint: hint(&settings.api_key),
|
||||||
|
app_key: settings.app_key.clone(),
|
||||||
|
access_key_set: !settings.access_key.is_empty(),
|
||||||
|
access_key_hint: hint(&settings.access_key),
|
||||||
|
resource_id: settings.resource_id.clone(),
|
||||||
|
endpoint: settings.endpoint.clone(),
|
||||||
|
hotwords: settings.hotwords.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hint(secret: &str) -> String {
|
||||||
|
let n = secret.chars().count();
|
||||||
|
if n == 0 {
|
||||||
|
return String::new();
|
||||||
|
}
|
||||||
|
if n <= 4 {
|
||||||
|
return "••••".into();
|
||||||
|
}
|
||||||
|
let tail: String = secret.chars().skip(n - 4).collect();
|
||||||
|
format!("••••{tail}")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load() -> SpeechSettings {
|
||||||
|
let Ok(entry) = keyring::Entry::new(KEYRING_SERVICE, KEYRING_USER) else {
|
||||||
|
return default_settings();
|
||||||
|
};
|
||||||
|
match entry.get_password() {
|
||||||
|
Ok(raw) => serde_json::from_str(&raw).unwrap_or_else(|_| default_settings()),
|
||||||
|
Err(_) => default_settings(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn save(settings: &SpeechSettings) -> AppResult<()> {
|
||||||
|
settings.validate()?;
|
||||||
|
let entry = keyring::Entry::new(KEYRING_SERVICE, KEYRING_USER)
|
||||||
|
.map_err(|e| AppError::new("keyring_failed", e.to_string()))?;
|
||||||
|
let raw = serde_json::to_string(settings)
|
||||||
|
.map_err(|e| AppError::new("settings_invalid", e.to_string()))?;
|
||||||
|
entry
|
||||||
|
.set_password(&raw)
|
||||||
|
.map_err(|e| AppError::new("keyring_failed", e.to_string()))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Empty secret fields keep the previously stored secret. Non-secret fields always overwrite.
|
||||||
|
pub fn merge_secrets(incoming: SpeechSettings, previous: &SpeechSettings) -> SpeechSettings {
|
||||||
|
let mut next = incoming;
|
||||||
|
if next.api_key.trim().is_empty() {
|
||||||
|
next.api_key = previous.api_key.clone();
|
||||||
|
}
|
||||||
|
if next.access_key.trim().is_empty() {
|
||||||
|
next.access_key = previous.access_key.clone();
|
||||||
|
}
|
||||||
|
next
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
|
"productName": "OOKIE 腾讯会议测试台",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"identifier": "school.oops.ookie.tx-meeting",
|
||||||
|
"build": {
|
||||||
|
"frontendDist": "../ui"
|
||||||
|
},
|
||||||
|
"app": {
|
||||||
|
"withGlobalTauri": true,
|
||||||
|
"windows": [
|
||||||
|
{
|
||||||
|
"label": "main",
|
||||||
|
"title": "OOKIE 腾讯会议测试台",
|
||||||
|
"width": 1180,
|
||||||
|
"height": 860,
|
||||||
|
"minWidth": 900,
|
||||||
|
"minHeight": 640
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"security": {
|
||||||
|
"csp": "default-src 'self'; script-src 'self'; style-src 'self'; connect-src ipc: http://ipc.localhost"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"bundle": {
|
||||||
|
"active": false,
|
||||||
|
"createUpdaterArtifacts": false,
|
||||||
|
"icon": ["icons/icon.ico", "icons/icon.png"]
|
||||||
|
}
|
||||||
|
}
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
:root {
|
||||||
|
color-scheme: light;
|
||||||
|
--ink: #1c1915;
|
||||||
|
--muted: #6d655c;
|
||||||
|
--line: #e4ddd4;
|
||||||
|
--paper: #f7f4ef;
|
||||||
|
--card: #fff;
|
||||||
|
--accent: #0f6e56;
|
||||||
|
--warn: #8a4b08;
|
||||||
|
font-family: "Segoe UI", "PingFang SC", "Noto Sans SC", sans-serif;
|
||||||
|
}
|
||||||
|
* { box-sizing: border-box; }
|
||||||
|
body { margin: 0; background: var(--paper); color: var(--ink); }
|
||||||
|
header, nav, main, footer { padding: 12px 20px; }
|
||||||
|
header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); background: var(--card); }
|
||||||
|
h1 { font-size: 18px; margin: 0; }
|
||||||
|
h2 { font-size: 14px; margin: 0 0 8px; }
|
||||||
|
p { margin: 4px 0; }
|
||||||
|
#account, .hint { color: var(--muted); font-size: 13px; }
|
||||||
|
.warn { color: var(--warn); font-size: 13px; }
|
||||||
|
.auth { font-size: 13px; padding: 4px 10px; border-radius: 99px; background: #efeae3; }
|
||||||
|
.auth.on { background: #d9f0e8; color: var(--accent); }
|
||||||
|
nav { display: flex; gap: 8px; }
|
||||||
|
nav button, button { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 7px 12px; cursor: pointer; }
|
||||||
|
nav button.on, button:not(.ghost) { background: var(--accent); color: white; border-color: var(--accent); }
|
||||||
|
button.ghost { background: transparent; }
|
||||||
|
.panel { display: none; }
|
||||||
|
.panel.on { display: block; }
|
||||||
|
.row, .card label { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
|
||||||
|
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-top: 14px; display: grid; gap: 8px; }
|
||||||
|
.card label { display: grid; gap: 4px; font-size: 13px; }
|
||||||
|
input, select, textarea { border: 1px solid var(--line); border-radius: 8px; padding: 8px; font: inherit; }
|
||||||
|
.list { list-style: none; padding: 0; display: grid; gap: 8px; }
|
||||||
|
.list li, .cols article { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
|
||||||
|
.cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
|
||||||
|
.log, .lines { background: #1c1915; color: #f4efe8; border-radius: 8px; padding: 10px; min-height: 80px; overflow: auto; font-size: 12px; white-space: pre-wrap; }
|
||||||
|
.lines { list-style: none; max-height: 420px; }
|
||||||
|
.lines .partial { opacity: 0.65; }
|
||||||
|
footer { position: sticky; bottom: 0; background: var(--card); border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
|
||||||
|
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } }
|
||||||
@@ -0,0 +1,224 @@
|
|||||||
|
const invoke = (...args) => window.__TAURI__.core.invoke(...args);
|
||||||
|
const listen = (...args) => window.__TAURI__.event.listen(...args);
|
||||||
|
|
||||||
|
const status = document.querySelector("#status");
|
||||||
|
const setStatus = (text) => { status.textContent = text; };
|
||||||
|
|
||||||
|
function showError(err) {
|
||||||
|
let detail = String(err);
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(detail);
|
||||||
|
detail = parsed.detail || parsed.code || detail;
|
||||||
|
} catch (_) { /* already a string */ }
|
||||||
|
setStatus(detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
document.querySelectorAll("nav button").forEach((button) => {
|
||||||
|
button.addEventListener("click", () => {
|
||||||
|
document.querySelectorAll("nav button, .panel").forEach((el) => el.classList.remove("on"));
|
||||||
|
button.classList.add("on");
|
||||||
|
document.querySelector("#" + button.dataset.tab).classList.add("on");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function pretty(value) {
|
||||||
|
if (value == null) return "";
|
||||||
|
if (typeof value === "string") return value;
|
||||||
|
return JSON.stringify(value, null, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshAuth() {
|
||||||
|
const view = await invoke("tmeet_status");
|
||||||
|
const node = document.querySelector("#auth");
|
||||||
|
node.textContent = view.summary;
|
||||||
|
node.classList.toggle("on", view.logged_in);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshMeetings() {
|
||||||
|
const data = await invoke("meeting_list");
|
||||||
|
const list = document.querySelector("#meeting-list");
|
||||||
|
const items = data.meeting_info_list || data.meetings || data.list || [];
|
||||||
|
const rows = Array.isArray(items) ? items : [];
|
||||||
|
list.innerHTML = "";
|
||||||
|
if (rows.length === 0) {
|
||||||
|
list.innerHTML = "<li>没有即将开始或进行中的会。原始返回已写在状态栏。</li>";
|
||||||
|
setStatus("会议列表为空,或字段名与预期不同");
|
||||||
|
list.insertAdjacentHTML("beforeend", `<li><pre class="log">${escapeHtml(pretty(data))}</pre></li>`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const item of rows) {
|
||||||
|
const li = document.createElement("li");
|
||||||
|
const subject = item.subject || item.meeting_subject || "未命名";
|
||||||
|
const code = item.meeting_code || "";
|
||||||
|
const start = item.start_time || "";
|
||||||
|
const end = item.end_time || "";
|
||||||
|
li.innerHTML = `<strong>${escapeHtml(subject)}</strong><div class="hint">${escapeHtml(String(code))} · ${escapeHtml(String(start))} – ${escapeHtml(String(end))}</div>`;
|
||||||
|
const row = document.createElement("div");
|
||||||
|
row.className = "row";
|
||||||
|
if (code) {
|
||||||
|
const join = document.createElement("button");
|
||||||
|
join.textContent = "入会";
|
||||||
|
join.onclick = () => invoke("meeting_launch", { meetingCode: String(code) }).then((plan) => setStatus(plan.note)).catch(showError);
|
||||||
|
row.appendChild(join);
|
||||||
|
}
|
||||||
|
const id = item.meeting_id;
|
||||||
|
if (id) {
|
||||||
|
const cancel = document.createElement("button");
|
||||||
|
cancel.className = "ghost";
|
||||||
|
cancel.textContent = "取消";
|
||||||
|
cancel.onclick = async () => {
|
||||||
|
if (!confirm(`取消「${subject}」?`)) return;
|
||||||
|
await invoke("meeting_cancel", { meetingId: String(id) }).catch(showError);
|
||||||
|
refreshMeetings().catch(showError);
|
||||||
|
};
|
||||||
|
row.appendChild(cancel);
|
||||||
|
}
|
||||||
|
li.appendChild(row);
|
||||||
|
list.appendChild(li);
|
||||||
|
}
|
||||||
|
setStatus(`${rows.length} 场即将开始或进行中`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeHtml(text) {
|
||||||
|
return text.replace(/[&<>"]/g, (ch) => ({ "&": "&", "<": "<", ">": ">", '"': """ }[ch]));
|
||||||
|
}
|
||||||
|
|
||||||
|
document.querySelector("#login").onclick = async () => {
|
||||||
|
setStatus("正在拉起客户端并等待浏览器授权,最多 5 分钟…");
|
||||||
|
try {
|
||||||
|
const result = await invoke("tmeet_login");
|
||||||
|
setStatus(result.focus || "授权流程已返回");
|
||||||
|
await refreshAuth();
|
||||||
|
await refreshMeetings();
|
||||||
|
} catch (err) { showError(err); }
|
||||||
|
};
|
||||||
|
|
||||||
|
document.querySelector("#logout").onclick = () => invoke("tmeet_logout").then(refreshAuth).then(() => setStatus("已登出")).catch(showError);
|
||||||
|
document.querySelector("#refresh").onclick = () => refreshMeetings().catch(showError);
|
||||||
|
|
||||||
|
document.querySelector("#preview").onclick = () => {
|
||||||
|
const form = new FormData(document.querySelector("#create"));
|
||||||
|
document.querySelector("#create-preview").textContent = pretty({
|
||||||
|
command: "tmeet meeting create",
|
||||||
|
subject: form.get("subject"),
|
||||||
|
start: form.get("start"),
|
||||||
|
end: form.get("end"),
|
||||||
|
note: "尚未调用。点确认建会才会真正创建。"
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
document.querySelector("#create").onsubmit = async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const form = new FormData(event.target);
|
||||||
|
if (!confirm("确认在你的个人腾讯会议账号下创建这场会议?")) return;
|
||||||
|
try {
|
||||||
|
const created = await invoke("meeting_create", {
|
||||||
|
subject: form.get("subject"),
|
||||||
|
start: form.get("start"),
|
||||||
|
end: form.get("end"),
|
||||||
|
});
|
||||||
|
document.querySelector("#create-preview").textContent = pretty(created);
|
||||||
|
setStatus("会议已创建");
|
||||||
|
refreshMeetings().catch(showError);
|
||||||
|
} catch (err) { showError(err); }
|
||||||
|
};
|
||||||
|
|
||||||
|
document.querySelector("#people-form").onsubmit = async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const code = new FormData(event.target).get("code");
|
||||||
|
try {
|
||||||
|
const meeting = await invoke("meeting_get", { meetingCode: code });
|
||||||
|
const id = meeting.meeting_id || meeting.meeting_info_list?.[0]?.meeting_id;
|
||||||
|
if (!id) {
|
||||||
|
document.querySelector("#invitees").textContent = pretty(meeting);
|
||||||
|
setStatus("查到了会议,但没有 meeting_id,无法拉人员");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const people = await invoke("meeting_people", { meetingId: String(id) });
|
||||||
|
document.querySelector("#invitees").textContent = pretty(people.invitees);
|
||||||
|
document.querySelector("#waiting").textContent = pretty(people.waitingRoom);
|
||||||
|
document.querySelector("#participants").textContent = pretty(people.participants);
|
||||||
|
setStatus(people.note);
|
||||||
|
} catch (err) { showError(err); }
|
||||||
|
};
|
||||||
|
|
||||||
|
document.querySelector("#join").onclick = async () => {
|
||||||
|
const code = new FormData(document.querySelector("#people-form")).get("code");
|
||||||
|
try {
|
||||||
|
const plan = await invoke("meeting_launch", { meetingCode: code });
|
||||||
|
setStatus(`${plan.note} ${plan.url}`);
|
||||||
|
} catch (err) { showError(err); }
|
||||||
|
};
|
||||||
|
|
||||||
|
function appendLine(payload) {
|
||||||
|
const list = document.querySelector("#lines");
|
||||||
|
if (payload.error) {
|
||||||
|
const li = document.createElement("li");
|
||||||
|
li.textContent = payload.error;
|
||||||
|
list.appendChild(li);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!payload.text) return;
|
||||||
|
let current = list.querySelector(".partial");
|
||||||
|
if (!current) {
|
||||||
|
current = document.createElement("li");
|
||||||
|
current.className = "partial";
|
||||||
|
list.appendChild(current);
|
||||||
|
}
|
||||||
|
const speaker = payload.speakerId ? `声音${payload.speakerId} · ` : "";
|
||||||
|
current.textContent = speaker + payload.text;
|
||||||
|
if (payload.definite) current.classList.remove("partial");
|
||||||
|
list.scrollTop = list.scrollHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
listen("transcript", (event) => appendLine(event.payload)).catch(showError);
|
||||||
|
|
||||||
|
document.querySelector("#test-asr").onclick = () => {
|
||||||
|
setStatus("正在用 fixture 音频测试豆包…");
|
||||||
|
invoke("speech_test").then((result) => setStatus(result.note)).catch(showError);
|
||||||
|
};
|
||||||
|
document.querySelector("#start-capture").onclick = () => {
|
||||||
|
invoke("capture_start").then((result) => setStatus(result.privacy)).catch(showError);
|
||||||
|
};
|
||||||
|
document.querySelector("#stop-capture").onclick = () => invoke("capture_stop").then(() => setStatus("已停止采集")).catch(showError);
|
||||||
|
|
||||||
|
async function loadSettings() {
|
||||||
|
const view = await invoke("speech_get");
|
||||||
|
const form = document.querySelector("#speech");
|
||||||
|
form.auth_mode.value = view.auth_mode || "new";
|
||||||
|
form.app_key.value = view.app_key || "";
|
||||||
|
form.resource_id.value = view.resource_id || "";
|
||||||
|
form.endpoint.value = view.endpoint || "";
|
||||||
|
form.hotwords.value = view.hotwords || "";
|
||||||
|
document.querySelector("#api-key-hint").textContent = view.api_key_set ? `已保存 ${view.api_key_hint}` : "未保存 API Key";
|
||||||
|
document.querySelector("#access-key-hint").textContent = view.access_key_set ? `已保存 ${view.access_key_hint}` : "未保存 Access Key";
|
||||||
|
}
|
||||||
|
|
||||||
|
document.querySelector("#speech").onsubmit = async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const form = new FormData(event.target);
|
||||||
|
try {
|
||||||
|
await invoke("speech_save", {
|
||||||
|
incoming: {
|
||||||
|
auth_mode: form.get("auth_mode"),
|
||||||
|
api_key: form.get("api_key") || "",
|
||||||
|
app_key: form.get("app_key") || "",
|
||||||
|
access_key: form.get("access_key") || "",
|
||||||
|
resource_id: form.get("resource_id"),
|
||||||
|
endpoint: form.get("endpoint"),
|
||||||
|
hotwords: form.get("hotwords") || "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
event.target.api_key.value = "";
|
||||||
|
event.target.access_key.value = "";
|
||||||
|
await loadSettings();
|
||||||
|
setStatus("语音设置已写入系统钥匙串");
|
||||||
|
} catch (err) { showError(err); }
|
||||||
|
};
|
||||||
|
|
||||||
|
invoke("app_info").then((info) => {
|
||||||
|
document.querySelector("#capture-note").textContent = info.capture;
|
||||||
|
document.querySelector("#account").textContent = info.limits[0];
|
||||||
|
}).catch(showError);
|
||||||
|
refreshAuth().catch(showError);
|
||||||
|
loadSettings().catch(showError);
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>OOKIE 腾讯会议测试台</title>
|
||||||
|
<link rel="stylesheet" href="app.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<div>
|
||||||
|
<h1>腾讯会议测试台</h1>
|
||||||
|
<p id="account">个人版 · 内置 tmeet · 豆包实时识别</p>
|
||||||
|
</div>
|
||||||
|
<div id="auth" class="auth">未检查</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<nav>
|
||||||
|
<button data-tab="meetings" class="on">会议</button>
|
||||||
|
<button data-tab="people">人员</button>
|
||||||
|
<button data-tab="transcript">转写</button>
|
||||||
|
<button data-tab="settings">设置</button>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<section id="meetings" class="panel on">
|
||||||
|
<div class="row">
|
||||||
|
<button id="login">连接腾讯会议</button>
|
||||||
|
<button id="logout" class="ghost">登出</button>
|
||||||
|
<button id="refresh">刷新会议</button>
|
||||||
|
</div>
|
||||||
|
<p class="hint">连接会先尝试拉起本机客户端,再打开浏览器完成授权。拉起本身拿不到 Token。客户端登录的个人账号必须和授权账号一致。</p>
|
||||||
|
<ul id="meeting-list" class="list"></ul>
|
||||||
|
|
||||||
|
<form id="create" class="card">
|
||||||
|
<h2>建一场面试</h2>
|
||||||
|
<label>主题 <input name="subject" value="面试" required /></label>
|
||||||
|
<label>开始 <input name="start" required placeholder="2026-11-14T15:00:00+08:00" /></label>
|
||||||
|
<label>结束 <input name="end" required placeholder="2026-11-14T16:00:00+08:00" /></label>
|
||||||
|
<div class="row">
|
||||||
|
<button type="button" id="preview">预览参数</button>
|
||||||
|
<button type="submit">确认建会</button>
|
||||||
|
</div>
|
||||||
|
<pre id="create-preview" class="log"></pre>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="people" class="panel">
|
||||||
|
<form id="people-form" class="row">
|
||||||
|
<input name="code" placeholder="9 位会议号" inputmode="numeric" />
|
||||||
|
<button type="submit">查询</button>
|
||||||
|
<button type="button" id="join">拉起客户端入会</button>
|
||||||
|
</form>
|
||||||
|
<p class="hint">受邀人是会前名单。参会明细是入会/离会记录,会还没开始时为空,不是接口失败。没有直播在线花名册。</p>
|
||||||
|
<div class="cols">
|
||||||
|
<article><h2>受邀人</h2><pre id="invitees" class="log"></pre></article>
|
||||||
|
<article><h2>等候室记录</h2><pre id="waiting" class="log"></pre></article>
|
||||||
|
<article><h2>参会明细</h2><pre id="participants" class="log"></pre></article>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="transcript" class="panel">
|
||||||
|
<div class="row">
|
||||||
|
<button id="test-asr">测试识别(fixture)</button>
|
||||||
|
<button id="start-capture">开始采集</button>
|
||||||
|
<button id="stop-capture" class="ghost">停止</button>
|
||||||
|
</div>
|
||||||
|
<p class="hint" id="capture-note"></p>
|
||||||
|
<p class="warn">候选人的声音会发到设置里填写的豆包服务。开始采集前需要已告知对方。豆包的说话人编号不是腾讯会议里的人名。</p>
|
||||||
|
<ol id="lines" class="lines"></ol>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="settings" class="panel">
|
||||||
|
<form id="speech" class="card">
|
||||||
|
<h2>豆包语音识别</h2>
|
||||||
|
<label>鉴权
|
||||||
|
<select name="auth_mode">
|
||||||
|
<option value="new">新版 API Key</option>
|
||||||
|
<option value="legacy">旧版 App Key + Access Key</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label>API Key <input name="api_key" type="password" autocomplete="off" placeholder="留空表示不修改" /></label>
|
||||||
|
<p class="hint" id="api-key-hint"></p>
|
||||||
|
<label>App Key <input name="app_key" autocomplete="off" /></label>
|
||||||
|
<label>Access Key <input name="access_key" type="password" autocomplete="off" placeholder="留空表示不修改" /></label>
|
||||||
|
<p class="hint" id="access-key-hint"></p>
|
||||||
|
<label>资源 ID <input name="resource_id" /></label>
|
||||||
|
<label>Endpoint <input name="endpoint" /></label>
|
||||||
|
<label>热词(一行一个) <textarea name="hotwords" rows="4"></textarea></label>
|
||||||
|
<button type="submit">保存到系统钥匙串</button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer id="status">就绪</footer>
|
||||||
|
<script src="app.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Vendored
+10
@@ -0,0 +1,10 @@
|
|||||||
|
# 内置 tmeet
|
||||||
|
|
||||||
|
来自 npm 包 `@tencentcloud/tmeet@1.1.0`(MIT)。
|
||||||
|
|
||||||
|
- `linux-x86_64/tmeet`:这台机器上的检查和开发用。
|
||||||
|
- `windows-x86_64/tmeet.exe`:打进 Windows 测试包,运行时放在 exe 旁边或由应用从 `vendor/tmeet/windows-x86_64/` 找到。
|
||||||
|
|
||||||
|
macOS 二进制没有放进来。Mac 包要在 Mac 上从同一个 npm 包取出 `tmeet-macOS-AppleSilicon` 或 `tmeet-macOS-Intel`。
|
||||||
|
|
||||||
|
凭证由 `tmeet` 自己加密进系统钥匙串(`~/.tmeet/`)。本应用不读取、不复制这份凭证。
|
||||||
BIN
Binary file not shown.
BIN
Binary file not shown.
Reference in New Issue
Block a user