# VoxSign VoxKeyboard — Windows 一键安装程序 # 用法: irm https://voxsign.net/download/win-install.ps1 | iex # 或直接双击下载的 .ps1 文件(需要以管理员身份运行) $center = "https://test.voxsign.net" $version = "2.11.21" $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' Write-Host "" Write-Host " ===========================================" -ForegroundColor Cyan Write-Host " VoxSign VoxKeyboard Windows 安装程序" -ForegroundColor Cyan Write-Host " 版本 $version" -ForegroundColor Cyan Write-Host " ===========================================" -ForegroundColor Cyan Write-Host "" $installDir = "$env:USERPROFILE\.voxsign" $venvDir = "$installDir\venv" $appScript = "$installDir\voxsign_tray.pyw" $logFile = "$installDir\install.log" $shortcut = "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\VoxSign.lnk" New-Item -ItemType Directory -Force -Path $installDir | Out-Null function Log($msg) { $ts = Get-Date -Format "HH:mm:ss" "$ts $msg" | Tee-Object -FilePath $logFile -Append | Out-Null Write-Host " $msg" } function Step($msg) { Write-Host "" Write-Host " >> $msg" -ForegroundColor Yellow } # ── Step 1: Python 3.11+ ──────────────────────────────────────────────────── Step "检查 Python 环境..." $pyCmd = $null foreach ($cmd in @("python", "python3", "py -3.11", "py")) { try { $ver = & $cmd --version 2>&1 if ($ver -match "Python 3\.(1[1-9]|[2-9]\d)") { $pyCmd = $cmd; break } } catch {} } if (-not $pyCmd) { Log "未检测到 Python 3.11+,正在下载安装..." $pyUrl = "https://www.python.org/ftp/python/3.11.9/python-3.11.9-amd64.exe" $pyInstaller = "$env:TEMP\python-3.11.9-amd64.exe" Invoke-WebRequest -Uri $pyUrl -OutFile $pyInstaller Start-Process -FilePath $pyInstaller -ArgumentList "/quiet InstallAllUsers=0 PrependPath=1 Include_test=0" -Wait # Reload PATH $env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "User") + ";" + $env:PATH $pyCmd = "python" Log "Python 3.11 安装完成" } else { $ver = & $pyCmd --version 2>&1 Log "找到 $ver" } # ── Step 2: 创建虚拟环境 ──────────────────────────────────────────────────── Step "创建虚拟环境..." if (-not (Test-Path "$venvDir\Scripts\python.exe")) { & $pyCmd -m venv $venvDir Log "虚拟环境创建完成: $venvDir" } else { Log "虚拟环境已存在,跳过" } $pip = "$venvDir\Scripts\pip.exe" $pypw = "$venvDir\Scripts\pythonw.exe" $py3 = "$venvDir\Scripts\python.exe" # ── Step 3: 安装依赖 ──────────────────────────────────────────────────────── Step "安装 VoxSign 组件(首次约需 1-2 分钟)..." & $pip install --upgrade pip --quiet & $pip install --upgrade pystray Pillow psutil --quiet Log "基础组件安装完成" # Optional: voxsign package (contains hardware_detector + installer_wizard) try { & $pip install --upgrade "voxsign[windows]" --quiet 2>$null Log "voxsign[windows] 安装完成" } catch { Log "voxsign 包安装跳过(将在首次运行时下载)" } # ── Step 4: 写入启动脚本 ──────────────────────────────────────────────────── Step "配置启动文件..." $launcherContent = @" # VoxSign Windows Tray Launcher import sys, os sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'site-packages')) from voxsign.windows.tray_app import main main() "@ Set-Content -Path $appScript -Value $launcherContent -Encoding UTF8 Log "启动脚本写入: $appScript" # ── Step 5: 开始菜单快捷方式 ──────────────────────────────────────────────── Step "创建开始菜单快捷方式..." $shell = New-Object -ComObject WScript.Shell $sc = $shell.CreateShortcut($shortcut) $sc.TargetPath = $pypw $sc.Arguments = "`"$appScript`"" $sc.WorkingDirectory = $installDir $sc.Description = "VoxSign 语音输入" $sc.IconLocation = "$pypw,0" $sc.Save() Log "快捷方式已创建" # ── Step 6: 开机自启动 ────────────────────────────────────────────────────── Step "设置开机自启动..." $regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" $startCmd = "`"$pypw`" `"$appScript`"" Set-ItemProperty -Path $regPath -Name "VoxSign" -Value $startCmd Log "开机自启动已注册" # ── 完成 ──────────────────────────────────────────────────────────────────── Write-Host "" Write-Host " ===========================================" -ForegroundColor Green Write-Host " 安装完成!正在启动 VoxSign..." -ForegroundColor Green Write-Host " ===========================================" -ForegroundColor Green Write-Host "" Write-Host " 系统托盘会出现 VoxSign 图标,首次启动会弹出配置向导" -ForegroundColor White Write-Host " 后续从开始菜单或开机自动启动" -ForegroundColor Gray Write-Host "" Start-Process -FilePath $pypw -ArgumentList "`"$appScript`"" -WindowStyle Hidden