@directus-labs/ai-transcription-operation
Advanced tools
Comparing version 1.0.5 to 1.1.0
@@ -1,1 +0,45 @@ | ||
import{request as r,log as e}from"directus:api";var t={id:"directus-labs-ai-transcription",handler:async({apiKey:t,url:a})=>{try{const e=await r("https://api.deepgram.com/v1/listen?model=nova-2&smart_format=true",{method:"POST",headers:{Authorization:`Token ${t}`,"Content-Type":"application/json"},body:JSON.stringify({url:a})});if(200!=e.status)throw new Error("An error occurred when accessing Deepgram");return e.data.results.channels[0].alternatives[0]}catch(r){throw e(r.message),new Error(r.message)}}};export{t as default}; | ||
import { request, log } from 'directus:api'; | ||
var api = { | ||
id: 'directus-labs-ai-transcription', | ||
handler: async ({ apiKey, url, callback, diarize, keywords }) => { | ||
// Because we're in an isolate environment, we need to manually construct the URL with string concatenation | ||
let requestUrl = 'https://api.deepgram.com/v1/listen?model=nova-2&smart_format=true'; | ||
if(callback) requestUrl += `&callback=${callback}`; | ||
if(diarize) requestUrl += `&diarize=${diarize}`; | ||
if(keywords && keywords.length > 0) { | ||
keywords.forEach(keyword => { | ||
requestUrl += `&keywords=${keyword}`; | ||
}); | ||
} | ||
try { | ||
const response = await request(requestUrl, { | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Token ${apiKey}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ url }) | ||
}); | ||
if(response.status != 200) throw new Error('An error occurred when accessing Deepgram') | ||
// If a callback URL was provided, we don't want to wait for the transcription to complete | ||
if(callback) { | ||
return { | ||
request_id: response.data.request_id, | ||
message: 'Transcription request submitted for processing.' | ||
} | ||
} | ||
else return response.data.results.channels[0].alternatives[0] | ||
} catch(error) { | ||
log(error.message); | ||
throw new Error(error.message) | ||
} | ||
}, | ||
}; | ||
export { api as default }; |
@@ -1,1 +0,75 @@ | ||
var e={id:"directus-labs-ai-transcription",name:"AI Transcription",icon:"hearing",description:"Use Deepgram's Speech Recognition API to generate transcripts from audio files.",overview:({url:e})=>[{label:"URL",text:e}],options:[{field:"apiKey",name:"Deepgram API Key",type:"string",required:!0,meta:{width:"full",interface:"input",options:{masked:!0}}},{field:"url",name:"File URL",type:"string",required:!0,meta:{width:"full",interface:"input"}}]};export{e as default}; | ||
var app = { | ||
id: 'directus-labs-ai-transcription', | ||
name: 'AI Transcription', | ||
icon: 'hearing', | ||
description: 'Use Deepgram\'s Speech Recognition API to generate transcripts from audio files.', | ||
overview: ({ url }) => [ | ||
{ | ||
label: 'URL', | ||
text: url, | ||
}, | ||
], | ||
options: [ | ||
{ | ||
field: 'apiKey', | ||
name: 'Deepgram API Key', | ||
type: 'string', | ||
meta: { | ||
width: 'full', | ||
required: true, | ||
interface: 'input', | ||
note: 'You can find or create an API key from the [Deepgram dashboard](https://console.deepgram.com/).', | ||
options: { | ||
masked: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
field: 'url', | ||
name: 'File URL', | ||
type: 'string', | ||
meta: { | ||
required: true, | ||
width: 'full', | ||
interface: 'input', | ||
note: 'Public URL of the file to transcribe.', | ||
}, | ||
}, | ||
{ | ||
field: 'callback', | ||
name: 'Callback URL', | ||
type: 'string', | ||
meta: { | ||
width: 'full', | ||
interface: 'input', | ||
note: 'Callback URL to provide if you would like your submitted audio to be processed asynchronously. [Learn more](https://developers.deepgram.com/docs/callback).', | ||
}, | ||
}, | ||
{ | ||
field: 'diarize', | ||
name: 'Diarization', | ||
type: 'boolean', | ||
meta: { | ||
width: 'half', | ||
interface: 'toggle', | ||
note: 'Indicates whether to recognize speaker changes. Defaults to `false`. [Learn more](https://developers.deepgram.com/docs/diarization).', | ||
}, | ||
}, | ||
{ | ||
field: 'keywords', | ||
name: 'Keywords', | ||
type: 'json', | ||
meta: { | ||
width: 'half', | ||
interface: 'tags', | ||
options: { | ||
placeholder: 'KEYWORD:INTENSIFIER and press Enter', | ||
}, | ||
note: 'Uncommon proper nouns or other words to transcribe that are not a part of the model’s vocabulary. Example: `KEYWORD:INTENSIFIER`. [Learn more](https://developers.deepgram.com/docs/keywords).' | ||
}, | ||
}, | ||
], | ||
}; | ||
export { app as default }; |
@@ -5,3 +5,3 @@ { | ||
"icon": "extension", | ||
"version": "1.0.5", | ||
"version": "1.1.0", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "keywords": [ |
@@ -7,4 +7,17 @@ # AI Transcription Operation | ||
This operation contains two required configuration options - a [Deepgram API Key](https://console.deepgram.com), and a link to a file. It returns a JSON object containing the transcript, a breakdown of each word and timestamp, a paragraph-formatted transcript, and a breakdown of each paragraph and timestamp. | ||
This operation contains the following configuration options: | ||
**Required** | ||
- [Deepgram API Key](https://console.deepgram.com) | ||
- File URL - public URL of the file to transcribe | ||
**Optional** | ||
- Callback URL - process the transcript asynchronously by providing a callback URL. The Deepgram API will make a POST request to this url once transcription is completed. | ||
- Diarization - include speaker changes in the transcript. | ||
- Keywords - Uncommon proper nouns or other words to transcribe that are not a part of the model’s vocabulary. These follow this format `keyword:intensifer`. | ||
--- | ||
If a Callback URL is NOT provided, the operation returns a JSON object containing the transcript, a breakdown of each word and timestamp, a paragraph-formatted transcript, and a breakdown of each paragraph and timestamp. | ||
![The output showing a JSON object containing a transcript and words.](https://raw.githubusercontent.com/directus-labs/extension-ai-transcription-operation/main/docs/output.png) | ||
@@ -14,5 +27,18 @@ | ||
--- | ||
If a Callback URL is provided, the operation does not wait for the transcript to finish generation. It immediately returns a JSON object containing the `request_id` provided by the Deepgram API and a message confirming successful submission. | ||
![The output showing a JSON object containing a confirmation message and request_id.](https://raw.githubusercontent.com/directus-labs/extension-ai-transcription-operation/main/docs/callback.png) | ||
The `request_id` should be stored and used to identify the incoming transcript from Deepgram. | ||
Once the transcript has been generated, the Deepgram API will make a `POST` request to the Callback URL you have provided. The `request_id` will be included in the metadata of that request. | ||
Make sure that your Callback URL is configured to accept and handle the response from Deepgram's API. This could be another Directus Flow with an incoming Webhook Trigger or some other system. | ||
## Output | ||
This operation outputs a JSON object with the following structure: | ||
If no Callback URL is provided, the operation outputs a JSON object with the following structure: | ||
@@ -46,3 +72,3 @@ ```json | ||
"end": 0.7075 | ||
} | ||
} | ||
] | ||
@@ -53,2 +79,11 @@ } | ||
If a Callback URL is provided, the operation outputs a JSON object with the following structure: | ||
```json | ||
{ | ||
"request_id": "42fc4c2b-09b3-4f5f-af04-3d1c9e9dc185", | ||
"message": "Transcription request submitted for processing." | ||
} | ||
``` | ||
## Flow Setup | ||
@@ -55,0 +90,0 @@ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
9470
111
112