feat: mac语音转换silk格式修复

This commit is contained in:
Wxw-Gu
2026-08-31 10:55:52 +08:00
parent 5acfa14475
commit 6cbf9af662
14 changed files with 970 additions and 12 deletions
@@ -0,0 +1,184 @@
import { useState } from 'react'
import type { PersonalWechatVoiceEncodingEnvironment } from '../../../../../shared/personal-wechat-voice-runtime'
import { Button } from '../../../components/ui'
import { isMac } from '../../../utils/runtime-environment'
function componentDetail(
component: PersonalWechatVoiceEncodingEnvironment['python'],
kind: 'python' | 'pilk' | 'ffmpeg'
): string {
if (!component.ready) {
const error = component.error || ''
if (/ENOENT|not found|未找到/i.test(error)) return '未找到'
if (kind === 'pilk' && /ModuleNotFoundError|No module named|未安装/i.test(error)) {
return '未安装'
}
return error || '未找到'
}
return [component.version, component.executable || component.path].filter(Boolean).join(' · ')
}
function statusLabel(environment: PersonalWechatVoiceEncodingEnvironment | null): string {
if (!environment) return '尚未检查'
if (environment.state === 'ready') return '✓ 编码环境正常'
if (environment.state === 'unsupported') return '当前系统不支持'
if (environment.state === 'error') return '检查失败'
return '⚠ 编码环境不完整'
}
function componentMark(ready: boolean): string {
return ready ? '✓' : '✗'
}
export function VoiceEncodingEnvironmentSection({
onNotice
}: {
onNotice: (message: string) => void
}): React.ReactElement | null {
const [environment, setEnvironment] = useState<PersonalWechatVoiceEncodingEnvironment | null>(
null
)
const [checking, setChecking] = useState(false)
const [installing, setInstalling] = useState(false)
if (!isMac) return null
const checkEnvironment = async (): Promise<void> => {
const check = window.api.checkPersonalWechatVoiceEncodingEnvironment
if (typeof check !== 'function') {
onNotice('当前版本暂不支持语音编码环境检查')
return
}
setChecking(true)
try {
setEnvironment(await check())
} catch (error) {
onNotice(error instanceof Error ? error.message : '语音编码环境检查失败')
} finally {
setChecking(false)
}
}
const installPilk = async (): Promise<void> => {
const install = window.api.installPersonalWechatPilk
if (typeof install !== 'function' || installing) {
if (typeof install !== 'function') onNotice('当前版本暂不支持 pilk 安装')
return
}
setInstalling(true)
try {
const result = await install()
setEnvironment(result.environment)
if (!result.success) {
onNotice(result.error || 'pilk 安装失败')
return
}
if (!result.environment.ready) {
onNotice(
result.environment.message || 'pilk 已安装,但仍有语音编码环境未就绪。请重新检查。'
)
} else if (result.restarted) {
onNotice('语音编码环境已修复,语音发送服务已重启')
} else if (result.restartError) {
onNotice(`语音编码环境已修复,但语音发送服务重启失败:${result.restartError}`)
} else {
onNotice('语音编码环境已修复。重新启动语音发送服务后生效。')
}
} catch (error) {
onNotice(error instanceof Error ? error.message : 'pilk 安装失败')
} finally {
setInstalling(false)
}
}
const openPythonDownload = async (): Promise<void> => {
const open = window.api.openPersonalWechatVoicePythonDownload
if (typeof open !== 'function') return onNotice('当前版本暂不支持打开 Python 下载页面')
const result = await open()
if (!result.success) onNotice(result.error || '无法打开 Python 下载页面')
}
const openFfmpegDownload = async (): Promise<void> => {
const open = window.api.openPersonalWechatVoiceFfmpegDownload
if (typeof open !== 'function') return onNotice('当前版本暂不支持打开 FFmpeg 安装页面')
const result = await open()
if (!result.success) onNotice(result.error || '无法打开 FFmpeg 安装页面')
}
const pythonMissing = Boolean(environment && !environment.python.ready)
const pilkMissing = Boolean(environment && !environment.pilk.ready && environment.python.ready)
const ffmpegMissing = Boolean(environment && !environment.ffmpeg.ready)
const status = environment?.state || 'unknown'
return (
<section className={`settings-card voice-encoding-environment status-${status}`}>
<div className="voice-encoding-heading">
<div>
<span className="settings-card-kicker">微信语音发送</span>
<h2>语音编码环境</h2>
<p>检查 TraceMemo 实际使用的 Python、pilk 和 FFmpeg,避免发送后才发现语音无法播放。</p>
</div>
<Button
variant="outline"
size="sm"
disabled={checking || installing}
onClick={() => void checkEnvironment()}
>
{checking ? '检查中…' : '检查编码环境'}
</Button>
</div>
<div className="voice-encoding-status" role="status">
<strong>{statusLabel(environment)}</strong>
{environment?.message ? <span>{environment.message}</span> : null}
</div>
{environment ? (
<div className="voice-encoding-checks">
<div
className={`voice-encoding-check ${environment.python.ready ? 'is-ready' : 'is-missing'}`}
>
<span>Python {componentMark(environment.python.ready)}</span>
<small>{componentDetail(environment.python, 'python')}</small>
{pythonMissing ? (
<Button variant="link" size="sm" onClick={() => void openPythonDownload()}>
安装 Python
</Button>
) : null}
</div>
<div
className={`voice-encoding-check ${environment.pilk.ready ? 'is-ready' : 'is-missing'}`}
>
<span>
pilk {environment.pilk.version || '0.2.4'} {componentMark(environment.pilk.ready)}
</span>
<small>{componentDetail(environment.pilk, 'pilk')}</small>
{pilkMissing ? (
<Button
variant="link"
size="sm"
disabled={installing}
onClick={() => void installPilk()}
>
{installing ? '安装中…' : '安装 pilk'}
</Button>
) : null}
</div>
<div
className={`voice-encoding-check ${environment.ffmpeg.ready ? 'is-ready' : 'is-missing'}`}
>
<span>ffmpeg {componentMark(environment.ffmpeg.ready)}</span>
<small>{componentDetail(environment.ffmpeg, 'ffmpeg')}</small>
{ffmpegMissing ? (
<Button variant="link" size="sm" onClick={() => void openFfmpegDownload()}>
安装 ffmpeg
</Button>
) : null}
</div>
</div>
) : (
<p className="voice-encoding-empty">点击“检查编码环境”后查看实际运行环境。</p>
)}
</section>
)
}
@@ -13,6 +13,7 @@ import {
SelectTrigger,
SelectValue
} from '../../../components/ui'
import { VoiceEncodingEnvironmentSection } from '../components/VoiceEncodingEnvironmentSection'
const VOICE_PAGE_SIZE = 24
@@ -432,6 +433,8 @@ export function TextToSpeechPage({
</ol>
</section>
<VoiceEncodingEnvironmentSection onNotice={onNotice} />
<h2 className="settings-section-heading">API 设置</h2>
<section className="settings-card tts-api-card">
<div className="tts-api-heading">
@@ -96,6 +96,123 @@
}
}
.voice-encoding-environment {
display: grid;
gap: 15px;
margin-bottom: 28px;
&.status-ready {
border-color: color-mix(in srgb, var(--wxex-success) 38%, var(--wxex-border));
}
&.status-incomplete,
&.status-error {
border-color: color-mix(in srgb, var(--wxex-warning) 42%, var(--wxex-border));
}
}
.voice-encoding-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18px;
h2 {
margin: 0;
color: var(--wxex-text-primary);
font-size: 16px;
}
p {
max-width: 620px;
margin: 5px 0 0;
color: var(--wxex-text-secondary);
font-size: 11px;
line-height: 17px;
}
}
.voice-encoding-status {
display: flex;
flex-wrap: wrap;
align-items: baseline;
gap: 8px;
padding: 9px 11px;
border-radius: var(--wxex-radius-sm);
background: var(--wxex-bg-main);
strong {
color: var(--wxex-text-primary);
font-size: 12px;
}
span {
color: var(--wxex-text-muted);
font-size: 11px;
}
.status-ready & strong {
color: var(--wxex-success);
}
.status-incomplete & strong,
.status-error & strong {
color: var(--wxex-warning);
}
}
.voice-encoding-checks {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 9px;
}
.voice-encoding-check {
min-width: 0;
display: grid;
gap: 4px;
align-content: start;
border: 1px solid var(--wxex-border);
border-radius: var(--wxex-radius-sm);
background: var(--wxex-bg-elevated);
padding: 10px 11px;
> span {
color: var(--wxex-text-primary);
font-size: 12px;
font-weight: 700;
}
&.is-ready > span {
color: var(--wxex-success);
}
&.is-missing > span {
color: var(--wxex-text-primary);
}
small {
min-height: 17px;
overflow: hidden;
color: var(--wxex-text-muted);
font-size: 10px;
line-height: 17px;
text-overflow: ellipsis;
white-space: nowrap;
}
button {
justify-self: start;
margin-top: 2px;
}
}
.voice-encoding-empty {
margin: 0;
color: var(--wxex-text-muted);
font-size: 11px;
}
.tts-auto-update-guide {
display: grid;
gap: 6px;
@@ -628,12 +745,17 @@
.tts-voice-grid {
grid-template-columns: 1fr;
}
.voice-encoding-checks {
grid-template-columns: 1fr;
}
}
@media (max-width: 720px) {
.tts-api-heading,
.tts-voice-heading,
.tts-api-footer,
.voice-encoding-heading,
.tts-usage-guide-heading {
align-items: stretch;
flex-direction: column;