UNPKG

@aituber-onair/voice

Version:

Voice synthesis library for AITuber OnAir

74 lines (73 loc) 2.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AudioPlayerFactory = exports.RuntimeDetection = void 0; const BrowserAudioPlayer_1 = require("./BrowserAudioPlayer"); const NodeAudioPlayer_1 = require("./NodeAudioPlayer"); /** * Runtime detection utility */ class RuntimeDetection { static isBrowser() { return typeof window !== 'undefined' && typeof document !== 'undefined'; } static isDeno() { return (typeof window !== 'undefined' && typeof globalThis.Deno !== 'undefined'); } static isBun() { return typeof globalThis.Bun !== 'undefined'; } static isNode() { return (typeof process !== 'undefined' && process.versions?.node !== undefined && !this.isBun()); } static getRuntimeName() { if (this.isBrowser()) return 'browser'; if (this.isDeno()) return 'deno'; if (this.isBun()) return 'bun'; if (this.isNode()) return 'node'; return 'unknown'; } } exports.RuntimeDetection = RuntimeDetection; /** * Factory class for creating environment-appropriate audio players */ class AudioPlayerFactory { /** * Create an audio player for the current environment */ static createAudioPlayer() { // Browser (including Deno which has window object) if (RuntimeDetection.isBrowser() || RuntimeDetection.isDeno()) { return new BrowserAudioPlayer_1.BrowserAudioPlayer(); } // Node.js and Bun (both can use Node.js audio libraries) if (RuntimeDetection.isNode() || RuntimeDetection.isBun()) { return new NodeAudioPlayer_1.NodeAudioPlayer(); } // Fallback to Node.js player for unknown environments return new NodeAudioPlayer_1.NodeAudioPlayer(); } /** * Get runtime information for debugging */ static getRuntimeInfo() { return { runtime: RuntimeDetection.getRuntimeName(), isBrowser: RuntimeDetection.isBrowser(), isDeno: RuntimeDetection.isDeno(), isBun: RuntimeDetection.isBun(), isNode: RuntimeDetection.isNode(), hasWindow: typeof window !== 'undefined', hasDocument: typeof document !== 'undefined', hasProcess: typeof process !== 'undefined', }; } } exports.AudioPlayerFactory = AudioPlayerFactory;