yum-slop/TaSTT

Free self-hosted STT for VRChat.

git clone https://git.yummers.dev/yum-slop/TaSTT

yumExperiment with hallucination reductiona7f9b7b

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