As soon as the user starts a dictation, send a request to the warmup endpoint. This prepares the connection for low latency operation by eliminating potential “cold start” delays.
Use connection keep-alive settings to maintain a persistent connection for the duration of your session. A recommended keep-alive timeout is 60 seconds. When the keep-alive period ends, send another warmup request to refresh the connection.
import requests# Create a session to reuse the connectionsession = requests.Session()# First, warm up the connectionsession.get("https://api.wisprflow.ai/api/v1/dash/warmup_dash")# Now use the warmed connection for the API calldef transcribe_audio(api_key, audio_base64): response = session.post( "https://api.flowvoice.ai/api/v1/dash/api", headers={ "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" }, json={ "audio": audio_base64, "properties": {} } ) return response.json()# Example usageapi_key = "your_api_key"audio_base64 = "UklGRiQA..." # Your base64 encoded audioresult = transcribe_audio(api_key, audio_base64)print(f"Transcription: {result['text']}")
JavaScript/TypeScript Example
Copy
Ask AI
async function warmupConnection(): Promise<boolean> { try { const response = await fetch('https://api.wisprflow.ai/api/v1/dash/warmup_dash'); return response.ok; } catch (error) { console.error('Warmup failed:', error); return false; }}// Import Axios and HTTPSimport axios from 'axios';import https from 'https';// Create an Axios client with keep-aliveconst client = axios.create({ baseURL: 'https://api.flowvoice.ai', httpsAgent: new https.Agent({ keepAlive: true, keepAliveMsecs: 60000, // 60 seconds maxSockets: 10 })});// Function to transcribe audio using the APIasync function transcribeAudio(apiKey: string, audioBase64: string): Promise<any> { try { const response = await client.post('/api/v1/dash/api', { audio: audioBase64, properties: {} }, { headers: { 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json' } }); return response.data; } catch (error) { console.error('API call failed:', error); throw error; }}// Example usage(async () => { const apiKey = 'your_api_key'; const audioBase64 = 'UklGRiQA...'; // Your base64 encoded audio // Warm up the connection const isWarmedUp = await warmupConnection(); if (isWarmedUp) { console.log('Connection warmed up successfully.'); } else { console.log('Failed to warm up the connection.'); } // Call the API try { const result = await transcribeAudio(apiKey, audioBase64); console.log(`Transcription: ${result.text}`); } catch (error) { console.error('Failed to transcribe audio:', error); }})();