yum-slop/TaSTT
Free self-hosted STT for VRChat.
git clone https://git.yummers.dev/yum-slop/TaSTT
a7f9b7b
master
1const { execSync} = require ( 'child_process' ); 2const path = require ( 'path' ); 3const fs = require ( 'fs' ); 4const https = require ( 'https' ); 5const { promisify} = require ( 'util' ); 6const stream = require ( 'stream' ); 7const pipeline = promisify ( stream . pipeline ); 8const extract = require ( 'extract-zip' ); 9 10const projectRoot = path . join ( __dirname , '..' , '..' ); 11const pythonPath = path . join ( projectRoot , 'python_embedded' ); 12const dllPath = path . join ( projectRoot , 'dll_empty' ); 13 14const PYTHON_URL = 'https://www.python.org/ftp/python/3.10.11/python-3.10.11-embed-amd64.zip' ; 15const PIP_URL = 'https://bootstrap.pypa.io/get-pip.py' ; 16 17async function downloadFile ( url , dest ) { 18console . log ( `Downloading ${ url } ...` ); 19const file = fs . createWriteStream ( dest ); 20 21return new Promise (( resolve , reject ) => { 22https . get ( url , ( response ) => { 23if ( response . statusCode === 302 || response . statusCode === 301 ) { 24// Handle redirect 25return downloadFile ( response . headers . location , dest ). then ( resolve ). catch ( reject ); 26} 27 28response . pipe ( file ); 29file . on ( 'finish' , () => { 30file . close (); 31console . log ( `Downloaded to ${ dest } ` ); 32resolve (); 33}); 34}). on ( 'error' , ( err ) => { 35fs . unlink ( dest , () => {}); // Delete the file on error 36reject ( err ); 37}); 38}); 39} 40 41async function setupEmbeddedPython () { 42console . log ( 'Setting up embedded Python...' ); 43 44// Delete existing directories 45if ( fs . existsSync ( pythonPath )) { 46fs . rmSync ( pythonPath , { recursive :true , force :true }); 47console . log ( 'Deleted existing Python directory' ); 48} 49if ( fs . existsSync ( dllPath )) { 50fs . rmSync ( dllPath , { recursive :true , force :true }); 51console . log ( 'Deleted existing dll directory' ); 52} 53 54// Create directories 55fs . mkdirSync ( pythonPath , { recursive :true }); 56fs . mkdirSync ( dllPath , { recursive :true }); 57console . log ( 'Created Python and dll directories' ); 58 59// Download Python 60const pythonZip = path . join ( projectRoot , 'python-3.10.11-embed-amd64.zip' ); 61if ( ! fs . existsSync ( pythonZip )) { 62await downloadFile ( PYTHON_URL , pythonZip ); 63} 64 65// Extract Python 66console . log ( 'Extracting Python...' ); 67await extract ( pythonZip , { dir :pythonPath }); 68console . log ( 'Python extracted successfully' ); 69 70// Update python310._pth to include the app directory and enable site packages 71const pthFile = path . join ( pythonPath , 'python310._pth' ); 72const pthContent = fs . readFileSync ( pthFile , 'utf8' ); 73fs . writeFileSync ( pthFile , pthContent + '\n../app\nimport site\n' ); 74console . log ( 'Updated python310._pth' ); 75 76// Download get-pip.py 77const getPipPath = path . join ( pythonPath , 'get-pip.py' ); 78await downloadFile ( PIP_URL , getPipPath ); 79 80// Install pip 81console . log ( 'Installing pip...' ); 82try { 83execSync ( `" ${ path . join ( pythonPath , 'python.exe' )} " " ${ getPipPath } "` , { 84stdio :'inherit' , 85cwd :pythonPath 86}); 87console . log ( 'pip installed successfully' ); 88} catch ( error ) { 89console . error ( 'Failed to install pip:' , error ); 90process . exit ( 1 ); 91} 92 93// Clean up 94fs . unlinkSync ( getPipPath ); 95 96console . log ( 'Embedded Python setup complete!' ); 97} 98 99// Run the setup 100setupEmbeddedPython (). catch ( err => { 101console . error ( 'Setup failed:' , err ); 102process . exit ( 1 ); 103}); 104