openaudio-sdk-npm
v1.3.0
Published
High-performance audio streaming SDK with real-time PCM output
Readme
OpenAudio SDK
High-performance audio streaming SDK with real-time PCM output and ultra-low latency (<500ms).
Features
- Ultra-Low Latency: First audio chunk delivered in under 500ms
- Real-Time Streaming: No buffering - audio streams as it's generated
- PCM Raw Output: Direct PCM audio data for maximum flexibility
- Multiple Formats: Support for PCM, WAV, and MP3
- WebSocket & SSE: Dual protocol support for reliability
- TypeScript: Full type safety and IntelliSense support
Installation
npm install openaudio-sdk-npmQuick Start
const OpenAudioSDK = require('openaudio-sdk-npm').default;
const sdk = new OpenAudioSDK('your-api-key');
// Stream PCM audio
const stream = await sdk.streamAudio('Hello world!', {
sampleRate: 16000,
bitDepth: 16,
lowLatency: true
});
stream.pipe(yourAudioPlayer);API Reference
Constructor
new OpenAudioSDK(apiKey: string, options?: {
baseUrl?: string;
timeout?: number;
maxRetries?: number;
})Methods
streamAudio(text: string, options?: StreamOptions)
Returns a readable stream of audio data.
generatePCM(text: string, options?: AudioRequest)
Returns a Buffer containing raw PCM data.
generateWAV(text: string, options?: AudioRequest)
Returns a Buffer containing WAV file data.
createPCMStream(text: string, options?: StreamOptions)
Returns a PCM-specific stream with parsing.
Events
latency: Fired when first chunk arrives with timing infoprogress: Continuous progress updates during streamingmetadata: Audio format metadatacomplete: Streaming completion statserror: Error handling
Options
interface AudioRequest {
voice?: string;
speed?: number;
pitch?: number;
volume?: number;
sampleRate?: 8000 | 16000 | 24000 | 32000 | 44100 | 48000;
bitDepth?: 8 | 16 | 24 | 32;
channels?: 1 | 2;
}
interface StreamOptions {
chunkSize?: number;
lowLatency?: boolean;
bufferSize?: number;
}Examples
See the /examples directory for complete examples:
basic-streaming.js- Simple PCM streamingpcm-to-wav.js- Generate WAV filesreal-time-playback.js- Direct speaker output
Performance
- First chunk latency: <500ms
- Streaming throughput: 100KB/s+
- Memory efficient chunked processing
License
MIT
