UNPKG

orate

Version:
2 lines (1 loc) 666 B
import{AssemblyAI as p}from"assemblyai";var o=class{constructor(t){let e=t||process.env.ASSEMBLYAI_API_KEY;if(!e)throw new Error("ASSEMBLYAI_API_KEY is not set");this.provider=new p({apiKey:e})}stt(t="best",e){return{generate:async i=>{let a=await i.arrayBuffer(),n=Buffer.from(a),s=await this.provider.transcripts.transcribe({audio:n,speech_model:t,...e});if(s.status==="error")throw new Error(s.error);for(;;){let r=await this.provider.transcripts.get(s.id);if(r.status==="error")throw new Error(r.error);if(r.status==="completed"){if(!r.text)throw new Error("No text returned.");return r.text}await new Promise(c=>setTimeout(c,1e3))}}}}};export{o as AssemblyAI};