YouTube Transcript API: Extract Video Captions & Speech-to-Text
Need to get the text content from YouTube videos? The Transcript API extracts captions and subtitles from any YouTube video—perfect for content analysis, SEO, and accessibility.
Why Use YouTube Transcripts?
- Content Repurposing - Turn videos into blog posts
- SEO Optimization - Extract keywords from video content
- Research - Analyze video content at scale
- Accessibility - Provide captions for all users
- Translation - Get multi-language transcripts
- AI Training - Build datasets from video content
Using the Transcript API
const response = await fetch(
'https://api.sociavault.com/v1/scrape/youtube/video/transcript?url=https://www.youtube.com/watch?v=dQw4w9WgXcQ',
{
headers: {
'x-api-key': 'YOUR_API_KEY'
}
}
);
const transcript = await response.json();
Parameters
| Parameter | Required | Description |
|---|---|---|
url | Yes | YouTube video URL |
Sample Response
Transcript segments are returned as an object with numeric keys. Use Object.values() to iterate.
{
"success": true,
"data": {
"type": "transcript",
"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"videoId": "dQw4w9WgXcQ",
"language": "en",
"transcript": {
"0": {
"text": "Welcome to today's video.",
"startMs": "0",
"endMs": "3500",
"startTimeText": "0:00"
},
"1": {
"text": "Today we're going to discuss...",
"startMs": "3500",
"endMs": "7200",
"startTimeText": "0:03"
}
},
"transcript_only_text": "Welcome to today's video. Today we're going to discuss...",
"captionTracks": {
"0": {
"baseUrl": "https://...",
"name": { "simpleText": "English" },
"languageCode": "en",
"kind": "asr",
"isTranslatable": true
}
}
},
"credits_used": 1
}
Use Cases
Convert Videos to Blog Posts
Extract content for written articles:
async function videoBlog(videoUrl) {
const res = await fetch(
`https://api.sociavault.com/v1/scrape/youtube/video/transcript?url=${encodeURIComponent(videoUrl)}`,
{ headers: { 'x-api-key': 'YOUR_API_KEY' } }
);
const { data } = await res.json();
// Use transcript_only_text for the full text
const blogContent = data.transcript_only_text
.replace(/\s+/g, ' ')
.split(/[.!?]+/)
.filter(s => s.trim().length > 0)
.map(s => s.trim() + '.')
.join('\n\n');
console.log(blogContent);
}
Extract Keywords for SEO
Analyze video content for keyword research:
async function extractKeywords(videoUrl) {
const res = await fetch(
`https://api.sociavault.com/v1/scrape/youtube/video/transcript?url=${encodeURIComponent(videoUrl)}`,
{ headers: { 'x-api-key': 'YOUR_API_KEY' } }
);
const { data } = await res.json();
const words = data.transcript_only_text.toLowerCase()
.replace(/[^\w\s]/g, '')
.split(/\s+/)
.filter(w => w.length > 3);
const wordFreq = {};
words.forEach(w => {
wordFreq[w] = (wordFreq[w] || 0) + 1;
});
const topKeywords = Object.entries(wordFreq)
.sort((a, b) => b[1] - a[1])
.slice(0, 20);
console.log('Top keywords:', topKeywords);
}
Create Timestamps
Generate chapter markers:
async function generateChapters(videoUrl) {
const res = await fetch(
`https://api.sociavault.com/v1/scrape/youtube/video/transcript?url=${encodeURIComponent(videoUrl)}`,
{ headers: { 'x-api-key': 'YOUR_API_KEY' } }
);
const { data } = await res.json();
const segments = Object.values(data.transcript);
const chapters = [];
let currentChapter = { startTimeText: '0:00', text: '' };
segments.forEach(segment => {
if (segment.text.includes('moving on') ||
segment.text.includes('next') ||
segment.text.includes('now let\'s talk about')) {
if (currentChapter.text) {
chapters.push(currentChapter);
}
currentChapter = {
startTimeText: segment.startTimeText,
text: segment.text
};
}
});
chapters.forEach(ch => {
console.log(`${ch.startTimeText} - ${ch.text}`);
});
}
Multi-Language Support
Check available caption tracks:
async function checkLanguages(videoUrl) {
const res = await fetch(
`https://api.sociavault.com/v1/scrape/youtube/video/transcript?url=${encodeURIComponent(videoUrl)}`,
{ headers: { 'x-api-key': 'YOUR_API_KEY' } }
);
const { data } = await res.json();
const tracks = Object.values(data.captionTracks);
console.log(`Language: ${data.language}`);
console.log('Available caption tracks:');
tracks.forEach(track => {
console.log(`- ${track.name.simpleText} (${track.languageCode})${track.isTranslatable ? ' [translatable]' : ''}`);
});
}
Content Analysis at Scale
Analyze multiple videos:
async function analyzeMultiple(videoUrls) {
const transcripts = await Promise.all(
videoUrls.map(async url => {
const res = await fetch(
`https://api.sociavault.com/v1/scrape/youtube/video/transcript?url=${encodeURIComponent(url)}`,
{ headers: { 'x-api-key': 'YOUR_API_KEY' } }
);
return (await res.json()).data;
})
);
// Combine all text for analysis
const allText = transcripts.map(t => t.transcript_only_text).join(' ');
// Run through your analysis pipeline
const insights = analyzeContent(allText);
}
## Related Endpoints
- [YouTube Video Details](/blog/youtube-video-details-api) - Video metadata
- [YouTube Videos Scraper](/blog/youtube-videos-scraper-api) - Channel videos
- [YouTube Comments](/blog/youtube-comments-scraper-api) - Video comments
- [TikTok Transcript](/blog/tiktok-transcript-api) - TikTok transcripts
- [Instagram Transcript](/blog/instagram-transcript-api) - Instagram transcripts
## Frequently Asked Questions
### What if a video has no captions?
If no captions exist, the API may not return transcript data. The `captionTracks` field shows available tracks — if `kind` is `"asr"`, the captions are auto-generated by YouTube.
### How many languages are supported?
The API returns whatever caption tracks YouTube has available. Check `captionTracks` in the response to see available languages. Tracks marked `isTranslatable: true` can be translated.
### Are timestamps included?
Yes, each transcript segment includes `startMs` and `endMs` (milliseconds) plus `startTimeText` (formatted as `"0:00"`). Use `Object.values(data.transcript)` to iterate.
### Can I get transcripts for live streams?
Live streams must end and process before transcripts are available. Recent live streams may not have transcripts yet.
### How accurate are auto-generated transcripts?
Auto-generated transcripts (where `captionTracks[].kind` is `"asr"`) typically achieve 90-95% accuracy for clear English speech. Accuracy varies with audio quality and language.
### Can I download SRT/VTT files?
The API returns structured data. You can convert the transcript segments to SRT format:
```javascript
function toSRT(transcript) {
const segments = Object.values(transcript);
return segments.map((seg, i) => {
const start = formatSRTTime(parseInt(seg.startMs));
const end = formatSRTTime(parseInt(seg.endMs));
return `${i + 1}\n${start} --> ${end}\n${seg.text}\n`;
}).join('\n');
}
function formatSRTTime(ms) {
const h = Math.floor(ms / 3600000);
const m = Math.floor((ms % 3600000) / 60000);
const s = Math.floor((ms % 60000) / 1000);
const mil = ms % 1000;
return `${String(h).padStart(2,'0')}:${String(m).padStart(2,'0')}:${String(s).padStart(2,'0')},${String(mil).padStart(3,'0')}`;
}
Get Started
Create your account and start extracting YouTube transcripts.
Documentation: /docs/api-reference/youtube/video-transcript
Found this helpful?
Share it with others who might benefit
Ready to Try SociaVault?
Start extracting social media data with our powerful API. No credit card required.