Skip to content

Feedback: guides-v2_to_v3_migration_js

Original URL: https://www.assemblyai.com/docs/guides/v2_to_v3_migration_js
Category: guides
Generated: 05/08/2025, 4:34:19 pm


Generated: 05/08/2025, 4:34:18 pm

Technical Documentation Analysis: AssemblyAI v2 to v3 Migration Guide

Section titled “Technical Documentation Analysis: AssemblyAI v2 to v3 Migration Guide”

This migration guide provides a comprehensive overview but suffers from several structural and clarity issues that could frustrate users during migration. The documentation jumps between high-level concepts and detailed implementation without clear transitions.

Issues:

  • The complete v3 code example at the beginning is overwhelming (200+ lines)
  • Step-by-step guide comes after the full implementation
  • No clear visual hierarchy between sections

Recommendations:

# Suggested Structure:
1. Quick Start / TL;DR section
2. Prerequisites & Dependencies
3. Key Differences Overview (table format)
4. Step-by-Step Migration Guide
5. Complete Working Example
6. Testing & Validation
7. Troubleshooting

Prerequisites Section Needed:

## Prerequisites
### Dependencies
Install required packages if not already present:
```bash
npm install ws mic querystring
  • Node.js version 12+
  • Valid AssemblyAI API key with streaming permissions
  • Microphone access permissions
  • Audio recording capabilities
  1. Get your API key from AssemblyAI Dashboard
  2. Replace "YOUR-API-KEY" in the code examples
### 3. **Unclear Message Schema Changes**
**Current Issue:** The message handling section is confusing with mixed old/new formats.
**Improved Format:**
```markdown
## Message Schema Changes
| v2 Field | v3 Field | Notes |
|----------|----------|-------|
| `message_type` | `type` | Field renamed |
| `session_id` | `id` | Field renamed |
| `text` | `transcript` | Field renamed |
| `SessionBegins` | `Begin` | Message type renamed |
| `PartialTranscript` | `Turn` (partial) | Combined into Turn type |
| `FinalTranscript` | `Turn` (formatted) | Use `turn_is_formatted` flag |
### New v3 Fields
- `expires_at`: Session expiration timestamp
- `turn_is_formatted`: Boolean indicating final vs partial transcript
- `audio_duration_seconds`: Total audio processed (Termination message)

4. Inadequate Error Handling Documentation

Section titled “4. Inadequate Error Handling Documentation”

Add Comprehensive Error Section:

## Error Handling & Common Issues
### Connection Errors
```javascript
ws.on("error", (error) => {
console.error(`WebSocket Error: ${error.message}`);
// Check common error causes
if (error.message.includes('401')) {
console.error('Authentication failed - check your API key');
} else if (error.message.includes('ECONNREFUSED')) {
console.error('Connection refused - check network connectivity');
}
cleanup();
});
// Add retry logic for connection failures
const MAX_RETRIES = 3;
let retryCount = 0;
function connectWithRetry() {
if (retryCount >= MAX_RETRIES) {
console.error('Max retries reached. Exiting.');
return;
}
// Connection logic here
retryCount++;
}
### 5. **Better Examples & Use Cases**
**Add Practical Examples:**
```markdown
## Configuration Examples
### Basic Streaming (Minimal Setup)
```javascript
const CONNECTION_PARAMS = {
sample_rate: 16000
};
const CONNECTION_PARAMS = {
sample_rate: 16000,
format_turns: true, // Get formatted final transcripts
enable_extra_session_information: true // Additional session stats
};
const CONNECTION_PARAMS = {
sample_rate: 16000,
format_turns: true,
word_boost: ["technical", "terminology"], // Boost specific words
boost_param: "high" // Increase boost strength
};
### 6. **Improved Testing Section**
**Expand Testing Guidance:**
```markdown
## Testing Your Migration
### 1. Unit Tests
```javascript
// Test message parsing
function testMessageParsing() {
const testMessage = '{"type":"Begin","id":"session_123","expires_at":1234567890}';
const parsed = JSON.parse(testMessage);
assert(parsed.type === "Begin");
assert(parsed.id === "session_123");
}
  • Test with 10-second audio clip
  • Verify partial transcripts arrive < 200ms
  • Confirm final transcripts are properly formatted
  • Test graceful shutdown (Ctrl+C)
  • Test continuous streaming for 5+ minutes
  • Monitor memory usage over time
  • Verify no WebSocket connection leaks
  • Invalid API key (expect 401)
  • Network disconnection during streaming
  • Malformed audio data
  • Rapid connect/disconnect cycles
### 7. **Add Troubleshooting Section**
```markdown
## Troubleshooting
### Issue: "Cannot connect to streaming endpoint"
**Symptoms:** WebSocket connection fails immediately
**Solutions:**
1. Verify API key is correct and has streaming permissions
2. Check firewall/proxy settings for WebSocket traffic
3. Ensure you're using the v3 endpoint URL
### Issue: "No audio being transcribed"
**Symptoms:** Connection successful but no transcription output
**Solutions:**
1. Verify microphone permissions
2. Check audio format (16kHz, 16-bit PCM)
3. Test with `mic.debug = true` to see audio data flow
### Issue: "High memory usage"
**Symptoms:** Memory increases over time during streaming
**Solutions:**
1. Ensure cleanup() is called on all exit paths
2. Clear recordedFrames array periodically if not needed
3. Monitor WebSocket connection state

Add Missing Section:

## Performance Optimization
### Audio Buffer Management
```javascript
// Limit recorded frames to prevent memory issues
const MAX_RECORDED_SECONDS = 300; // 5 minutes
const MAX_FRAMES = MAX_RECORDED_SECONDS * SAMPLE_RATE / 1024;
micInputStream.on("data", (data) => {
// Trim old frames if buffer gets too large
if (recordedFrames.length > MAX_FRAMES) {
recordedFrames = recordedFrames.slice(-MAX_FRAMES);
}
recordedFrames.push(Buffer.from(data));
if (ws && ws.readyState === WebSocket.OPEN) {
ws.send(data);
}
});
  • Use connection pooling for multiple sessions
  • Implement exponential backoff for reconnections
  • Monitor session expiration times
### 9. **Security Considerations**
**Add Security Section:**
```markdown
## Security Best Practices
### API Key Management
- Never commit API keys to version control
- Use environment variables: `process.env.ASSEMBLYAI_API_KEY`
- Rotate keys regularly in production environments
### Audio Data Privacy
- The provided example saves audio locally - consider privacy implications
- Implement secure deletion of temporary audio files
- Consider encrypting stored audio data
  1. High Priority:

    • Add prerequisites and dependencies section at the top
    • Create a comparison table for v2 vs v3 differences
    • Move the complete code example after the step-by-step guide
    • Add comprehensive error handling examples
  2. Medium Priority:

    • Expand testing section with specific test cases
    • Add troubleshooting section with common issues
    • Include performance optimization guidance
    • Add security considerations
  3. Low Priority:

    • Improve code comment explanations
    • Add links to related documentation
    • Include estimated migration time
    • Add changelog/version history reference

This restructured approach would significantly improve user experience and reduce