async function warmupConnection(): Promise<boolean> {
try {
const response = await fetch('https://platform-api.wisprflow.ai/api/v1/dash/warmup_dash');
return response.ok;
} catch (error) {
console.error('Warmup failed:', error);
return false;
}
}
// Import Axios and HTTPS
import axios from 'axios';
import https from 'https';
// Create an Axios client with keep-alive
const 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 API
async 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);
}
})();