Get YouTube Video Transcription with an API call
In this blog post, we will create an automated workflow to download and transcribe YouTube videos via DataFlow Platform's API. This tutorial demonstrates building and executing a workflow as standalone automation process accessible via API or web interface.
Workflow
The main execution unit of the DataFlow Platform is a workflow. A workflow is a sequence of tasks that are executed in order.
For this workflow, we need to have the following automation steps:
- Receive a YouTube video URL as an input.
- Download a YouTube video by its URL.
- Extract the video's audio.
- Use a cloud AI service to transcribe the audio.
- Return the transcription as a response.
Unit of work in DataFlow Platform is a task. A task is a single unit of work that can be executed in a workflow. With the task types, we can implement the automation steps.
We need the following task types to implement this workflow:
- Youtube Downloader: To download the YouTube video
- Extract Audio from Video: To extract the video's audio
- Call AI Service: To transcribe the video (OpenAI Whisper)
To have this automation via the platform, we need first to create a workflow unit with all the tasks, and connect these tasks.
Workflow to Automate the Process
Here is the initial version of the workflow defined in JSON format:
{
"title": "YouTube Video Transcription Workflow using Speech-to-Text AI model",
"description": "Downloads a YouTube video, extracts audio, transcribes it using OpenAI's Whisper model, and returns the transcription text",
"inputs": [
{
"name": "youtube_url",
"type": "text",
"description": "The URL of the YouTube video to transcribe"
}
],
"tasks": [
{
"name": "download_video",
"type": "youtube.download",
"inputs": {
"youtube_url": "{{inputs.youtube_url}}"
}
},
{
"name": "extract_audio",
"type": "video.extract_audio",
"inputs": {
"video": "{{tasks.download_video.outputs.video}}"
}
},
{
"name": "transcribe_audio",
"type": "openai.audio.transcribe",
"inputs": {
"file": "{{tasks.extract_audio.outputs.audio}}",
"model": "whisper-1"
}
}
],
"outputs": [
{
"name": "transcription_text",
"type": "text",
"value": "{{tasks.transcribe_audio.outputs.text}}",
"description": "The transcribed text of the YouTube video's audio"
}
]
}
Create a Workflow
To create a workflow, you can use the following command:
curl -X POST \
-H "Content-Type: application/json" \
-d @workflow.json \
https://api.dataflow.wiki/workflows
If the workflow is created successfully, you will receive a response with the Workflow ID.
{
"workflow_id": "wf-4g7h8j9k"
}
Save the Workflow ID, we will need it to execute the workflow.
Execute the Workflow
To execute the workflow, you need to send a POST request to the /workflows/{{workflow-id}}/executions
endpoint with the input data for the workflow.
API Request:
POST /workflows/{{workflow-id}}/executions
Headers:
- Content-Type: application/json
- X-OpenAI-Key: your_openai_api_key
Request Body:
{
"inputs": {
"youtube_url": "https://www.youtube.com/watch?v=00000000000"
}
}
The CURL version of the request would look like this:
curl -X POST \
-H "Content-Type: application/json" \
-H "X-OpenAI-Key: your_openai_api_key" \
-d '{"inputs": {"youtube_url": "https://www.youtube.com/watch?v=00000000000"}, "monitoring": {"webhook_url": "https://example.com/webhook"}}' \
https://api.dataflow.wiki/workflows/{{workflow-id}}/executions
Since this workflow uses OpenAI's Whisper model, you must also include your OpenAI API key in the request header.
Data Flow Platform uses provided API keys only for the tasks that require them and does not store them for future use.
Extend
- Provide input and output language options
- Provide a way to save the transcription to a remote file storage
For detailed documentation and examples, visit our Documentation Portal.