mbz-voice-sdk
Version:
šļø MBZ Voice SDK: Easily add voice recognition, Gemini-based AI replies, and TTS to any web app.
79 lines (61 loc) ⢠2.88 kB
JavaScript
import fs from 'fs';
import path from 'path';
import readline from 'readline';
import { fileURLToPath } from 'url';
// Compatibility for ES module __dirname
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// CLI prompt setup
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// Template paths
const templatesDir = path.join(__dirname, "templates");
const backendSrc = path.join(templatesDir, "backend");
const frontendSrc = path.join(templatesDir, "frontend");
// Helper to copy all files from one folder to another
function copyFolderContents(srcDir, destDir) {
if (!fs.existsSync(destDir)) fs.mkdirSync(destDir, { recursive: true });
const files = fs.readdirSync(srcDir);
files.forEach((file) => {
const srcFile = path.join(srcDir, file);
const destFile = path.join(destDir, file);
fs.copyFileSync(srcFile, destFile);
});
}
// Prompt user to scaffold
rl.question("š§ Create MBZ Voice SDK project with backend and frontend? (y/n): ", (answer) => {
if (answer.toLowerCase() === 'y') {
copyFolderContents(backendSrc, path.resolve("backend"));
console.log("ā
backend/ created");
copyFolderContents(frontendSrc, path.resolve("frontend"));
console.log("ā
frontend/ created");
console.log("\nš MBZ Voice SDK setup complete!\n");
console.log("š Created:");
console.log(" āāā backend/ ā FastAPI Gemini server");
console.log(" āāā frontend/ ā HTML + JS voice client\n");
console.log("š Backend Setup:");
console.log("1ļøā£ cd backend");
console.log(" pip install -r requirements.txt");
console.log(" cp .env.example .env # Add your Gemini API key from https://makersuite.google.com/app/apikey");
console.log(" uvicorn main:app --reload\n");
console.log("š Frontend Setup:");
console.log("2ļøā£ cd frontend");
console.log(" ā ļø Do NOT double-click index.html ā it will block script.js due to CORS.");
console.log("\nā
Recommended Way (Live Server):");
console.log(" - Open folder in VS Code");
console.log(" - Install 'Live Server' extension by Ritwick Dey");
console.log(" - Right-click index.html ā Open with Live Server");
console.log("\nš” Or Use Python Server:");
console.log(" python -m http.server 8000");
console.log(" Open http://localhost:8000 in Chrome");
console.log("\nš¼ Make sure logo.png exists in /frontend and matches this file name exactly.");
console.log("š Click 'Start Talking' to test the AI voice SDK.");
console.log("\nš You're now ready to build with MBZ Voice SDK!");
} else {
console.log("ā Cancelled.");
}
rl.close();
});