/** * Inflect-Micro-v2 TTS CLI * * Usage: tts_cli --text "Hello world" --output output.wav [--speed 1.0] * * Build: cmake .. && make tts_cli */ #include #include #include #include #include #include "inflect_tts.hpp" static void print_usage(const char* prog) { std::cerr << "Usage: " << prog << " --text [--output out.wav] [--speed 1.0]\n"; std::cerr << "Options:\n"; std::cerr << " --text Text to synthesize (required)\n"; std::cerr << " --output Output file path (default: output.wav)\n"; std::cerr << " --speed Playback speed 0.5-2.0 (default: 1.0)\n"; std::cerr << " --variation Voice variation 0.0-1.0 (default: 0.667)\n"; } int main(int argc, char* argv[]) { std::string text; std::string output = "output.wav"; float speed = 1.0f; float variation = 0.667f; // Parse arguments for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "--text") == 0 && i + 1 < argc) text = argv[++i]; else if (strcmp(argv[i], "--output") == 0 && i + 1 < argc) output = argv[++i]; else if (strcmp(argv[i], "--speed") == 0 && i + 1 < argc) speed = std::stof(argv[++i]); else if (strcmp(argv[i], "--variation") == 0 && i + 1 < argc) variation = std::stof(argv[++i]); else if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) { print_usage(argv[0]); return 0; } } if (text.empty()) { std::cerr << "Error: --text is required\n"; print_usage(argv[0]); return 1; } std::cout << "🎤 Text: " << text << "\n"; std::cout << "📁 Output: " << output << "\n"; try { TTSEngine engine("../models/inflect_encoder.axmodel", "../models/inflect_decoder.axmodel"); auto t0 = std::chrono::steady_clock::now(); auto waveform = engine.synthesize(text, speed, variation); auto t1 = std::chrono::steady_clock::now(); double elapsed = std::chrono::duration(t1 - t0).count(); double duration = waveform.size() / 24000.0; std::cout << "✅ Done! " << duration << "s audio, RTF=" << elapsed/duration << "x\n"; // Write WAV (simplified: raw float32 for now, use libsndfile for proper WAV) std::ofstream out(output, std::ios::binary); out.write(reinterpret_cast(waveform.data()), waveform.size() * sizeof(float)); std::cout << "🔊 " << output << "\n"; } catch (const std::exception& e) { std::cerr << "❌ Error: " << e.what() << "\n"; return 1; } return 0; }