Created
May 16, 2023 17:20
-
-
Save ploeber/9adda06b3d932601769f6f7204f55020 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const baseUrl = 'https://api.assemblyai.com/v2' | |
const createTranscript = async (z, bundle) => { | |
const data = { | |
audio_url: "https://storage.googleapis.com/aai-docs-samples/nbc.mp3" | |
} | |
const transcriptUrl = baseUrl + '/transcript' | |
const options = { | |
method: 'POST', | |
url: transcriptUrl, | |
body: JSON.stringify(data), | |
}; | |
const transcriptResponse = await z.request(options); | |
const transcriptId = transcriptResponse.data.id | |
const pollingEndpoint = `${baseUrl}/transcript/${transcriptId}` | |
while (true) { | |
const pollingResponse = await z.request({ | |
method: 'GET', | |
url: pollingEndpoint, | |
}); | |
const transcriptionResult = pollingResponse.data | |
if (transcriptionResult.status === 'completed') { | |
return transcriptionResult; | |
} else if (transcriptionResult.status === 'error') { | |
throw new z.errors.Error( | |
`Transcription failed: ${transcriptionResult.error}`, | |
'TranscriptError', | |
pollingResponse.status | |
); | |
} else { | |
await new Promise((resolve) => setTimeout(resolve, 3000)) | |
} | |
} | |
}; | |
module.exports = { | |
key: 'transcript', | |
noun: 'Transcript', | |
display: { | |
label: 'Create Transcript', | |
description: 'Creates a transcript using the AssemblyAI API.' | |
}, | |
operation: { | |
inputFields: [], | |
perform: createTranscript | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment