Skills Plugins MCP Prompt Model 博客 我的中心

asr

Implement speech-to-text (ASR/automatic speech recognition) capabilities using the z-ai-web-dev-sdk. Use this skill when the user needs to transcribe audio files, convert speech to text, build voice input features, or process audio recordings. Supports base64 encoded audio files and returns accurate text transcriptions.

DeepseekModel 官方收录技能 质量 良好 · 64 v1.0.0

获取

https://deepseekmodel.com/api/download.php?id=answerzhao-agent-skills-glm-skills-asr-skill-md&format=skill
下载 .skill 标准格式,含 system_prompt 与 model_config,导入任意 Agent 框架即可使用
.skill 文件中 system_prompt 字段的实际内容。
name ASR description Implement speech-to-text (ASR/automatic speech recognition) capabilities using the z-ai-web-dev-sdk. Use this skill when the user needs to transcribe audio files, convert speech to text, build voice input features, or process audio recordings. Supports base64 encoded audio files and returns accurate text transcriptions. license MIT ASR (Speech to Text) Skill This skill guides the implementation of speech-to-text (ASR) functionality using the z-ai-web-dev-sdk package, enabling accurate transcription of spoken audio into text. Skills Path Skill Location : {project_path}/skills/ASR this skill is located at above path in your project. Reference Scripts : Example test scripts are available in the {Skill Location}/scripts/ directory for quick testing and reference. See {Skill Location}/scripts/asr.ts for a working example. Overview Speech-to-Text (ASR - Automatic Speech Recognition) allows you to build applications that convert spoken language in audio files into written text, enabling voice-controlled interfaces, transcription services, and audio content analysis. IMPORTANT : z-ai-web-dev-sdk MUST be used in backend code only. Never use it in client-side code. Prerequisites The z-ai-web-dev-sdk package is already installed. Import it as shown in the examples below. CLI Usage (For Simple Tasks) For simple audio transcription tasks, you can use the z-ai CLI instead of writing code. This is ideal for quick transcriptions, testing audio files, or batch processing. Basic Transcription from File # Transcribe an audio file z-ai asr --file ./audio.wav # Save transcription to JSON file z-ai asr -f ./recording.mp3 -o transcript.json # Transcribe and view output z-ai asr --file ./interview.wav --output result.json Transcription from Base64 # Transcribe from base64 encoded audio z-ai asr -- base64 "UklGRiQAAABXQVZFZm10..." -o result.json # Using short option z-ai asr -b "base64_encoded_audio_data" -o transcript.json Streaming Output # Stream transcription results z-ai asr -f ./audio.wav --stream CLI Parameters --file, -f <path> : Required (if not using --base64) - Audio file path --base64, -b <base64> : Required (if not using --file) - Base64 encoded audio --output, -o <path> : Optional - Output file path (JSON format) --stream : Optional - Stream the transcription output Supported Audio Formats The ASR service supports various audio formats including: WAV (.wav) MP3 (.mp3) Other common audio formats When to Use CLI vs SDK Use CLI for: Quick audio file transcriptions Testing audio recognition accuracy Simple batch processing scripts One-off transcription tasks Use SDK for: Real-time audio transcription in applications Integration with recording systems Custom audio processing workflows Production applications with streaming audio Basic ASR Implementation Simple Audio Transcription import ZAI from 'z-ai-web-dev-sdk' ; import fs from 'fs' ; async function transcribeAudio ( audioFilePath ) { const zai = await ZAI . create (); // Read audio file and convert to base64 const audioFile = fs. readFileSync (audioFilePath); const base64Audio = audioFile. toString ( 'base64' ); const response = await zai. audio . asr . create ({ file_base64 : base64Audio }); return response. text ; } // Usage const transcription = await transcribeAudio ( './audio.wav' ); console . log ( 'Transcription:' , transcription); Transcribe Multiple Audio Files import ZAI from 'z-ai-web-dev-sdk' ; import fs from 'fs' ; async function transcribeBatch ( audioFilePaths ) { const zai = await ZAI . create (); const results = []; for ( const filePath of audioFilePaths) { try { const audioFile = fs. readFileSync (filePath); const base64Audio = audioFile. toString ( 'base64' ); const response = await zai. audio . asr . create ({ file_base64 : base64Audio }); results. push ({ file : filePath, success : true , transcription : response. text }); } catch (error) { results. push ({ file : filePath, success : false , error : error. message }); } } return results; } // Usage const files = [ './interview1.wav' , './interview2.wav' , './interview3.wav' ]; const transcriptions = await transcribeBatch (files); transcriptions. forEach ( result => { if (result. success ) { console . log ( ` ${result.file} : ${result.transcription} ` ); } else { console . error ( ` ${result.file} : Error - ${result.error} ` ); } }); Advanced Use Cases Audio File Processing with Metadata import ZAI from 'z-ai-web-dev-sdk' ; import fs from 'fs' ; import path from 'path' ; async function transcribeWithMetadata ( audioFilePath ) { const zai = await ZAI . create (); // Get file metadata const stats = fs. statSync (audioFilePath); const audioFile = fs. readFileSync (audioFilePath); const base64Audio = audioFile. toString ( 'base64' ); const startTime = Date . now (); const response = await zai. audio . asr . create ({ file_base64 : base64Audio }); const endTime = Date . now (); return { filename : path. basename (audioFilePath), filepath : audioFilePath, fileSize : stats. size , transcription : response. text , wordCount : response. text . split ( /\s+/ ). length , processingTime : endTime - startTime, timestamp : new Date (). toISOString () }; } // Usage const result = await transcribeWithMetadata ( './meeting_recording.wav' ); console . log ( 'Transcription Details:' , JSON . stringify (result, null , 2 )); Real-time Audio Processing Service import ZAI from 'z-ai-web-dev-sdk' ; import fs from 'fs' ; class ASRService { constructor ( ) { this . zai = null ; this . transcriptionCache = new Map (); } async initialize ( ) { this . zai = await ZAI . create (); } generateCacheKey ( audioBuffer ) { const crypto = require ( 'crypto' ); return crypto. createHash ( 'md5' ). update (audioBuffer). digest ( 'hex' ); } async transcribe ( audioFilePath, useCache = true ) { const audioBuffer = fs. readFileSync (audioFilePath); const cacheKey = this . generateCacheKey (audioBuffer); // Check cache if (useCache && this . transcriptionCache . has (cacheKey)) { return { transcription : this . transcriptionCache . get (cacheKey), cached : true }; } // Transcribe audio const base64Audio = audioBuffer. toString ( 'base64' ); const response = await this . zai . audio . asr . create ({ file_base64 : base64Audio }); // Cache result if (useCache) { this . transcriptionCache . set (cacheKey, response. text ); } return { transcription : response. text , cached : false }; } clearCache ( ) { this . transcriptionCache . clear (); } getCacheSize ( ) { return this . transcriptionCache . size ; } } // Usage const asrService = new ASRService (); await asrService. initialize (); const result1 = await asrService. transcribe ( './audio.wav' ); console . log ( 'First call (not cached):' , result1); const result2 = await asrService. transcribe ( './audio.wav' ); console . log ( 'Second call (cached):' , result2); Directory Transcription import ZAI from 'z-ai-web-dev-sdk' ; import fs from 'fs' ; import path from 'path' ; async function transcribeDirectory ( directoryPath, outputJsonPath ) { const zai = await ZAI . create (); // Get all audio files const files = fs. readdirSync (directoryPath); const audioFiles = files. filter ( file => /\.(wav|mp3|m4a|flac|ogg)$/i . test (file) ); const results = { directory : directoryPath, totalFiles : audioFiles. length , processedAt : new Date (). toISOString (), transcriptions : [] }; for ( const filename of audioFiles) { const filePath = path. join (directoryPath, filename); try { const audioFile = fs. readFileSync (filePath); const base64Audio = audioFile. toString ( 'base64' ); const response = await zai. audio . asr . create ({ file_base64 : base64Audio }); results. transcriptions . push ({ filename : filename, success : true , text : response. text , wordCount : response. text . split ( /\s+/ ). length }); console . log ( `✓ Transcribed: ${filename} ` ); } catch (error) { results. transcriptions . push ({ filename : filename, success : false , error : error. message }); console . error ( `✗ Failed: ${filename} - ${error.message} ` ); } } // Save results to JSON fs. writeFileSync ( outputJsonPath, JSON . stringify (results, null , 2 ) ); return results; } // Usage const results = await transcribeDirectory ( './audio-recordings' , './transcriptions.json' ); console . log ( `\nProcessed ${results.totalFiles} files` ); console . log ( `Successful: ${results.transcriptions.filter(t => t.success).length} ` ); console . log ( `Failed: ${results.transcriptions.filter(t => !t.success).length} ` ); Best Practices 1. Audio Format Handling import ZAI from 'z-ai-web-dev-sdk' ; import fs from 'fs' ; async function transcribeAnyFormat ( audioFilePath ) { // Supported formats: WAV, MP3, M4A, FLAC, OGG, etc. const validExtensions = [ '.wav' , '.mp3' , '.m4a' , '.flac' , '.ogg' ]; const ext = audioFilePath. toLowerCase (). substring (audioFilePath. lastIndexOf ( '.' )); if (!validExtensions. includes (ext)) { throw new Error ( `Unsupported audio format: ${ext} ` ); } const zai = await ZAI . create (); const audioFile = fs. readFileSync (audioFilePath); const base64Audio = audioFile. toString ( 'base64' ); const response = await zai. audio . asr . create ({ file_base64 : base64Audio }); return response. text ; } 2. Error Handling import ZAI from 'z-ai-web-dev-sdk' ; import fs from 'fs' ; async function safeTranscribe ( audioFilePath ) { try { // Validate file exists if (!fs. existsSync (audioFilePath)) { throw new Error ( `File not found: ${audioFilePath} ` ); } // Check file size (e.g., limit to 100MB) const stats = fs. statSync (audioFilePath); const fileSizeMB = stats. size / ( 1024 * 1024 ); if (fileSizeMB > 100 ) { throw new Error ( `File too large: ${fileSizeMB.toFixed( 2 )} MB (max 100MB)` ); } // Transcribe const zai = await ZAI . create (); const audioFile = fs. readFileSync (audioFilePath); const base64Audio = audioFile. toString ( 'base64' ); const response = await zai. audio . asr . create ({ file_base64 : base64Audio }); if (!response. text || response. text . trim (). length === 0 ) { throw new Error ( 'Empty transcription result' ); } return { success : true , transcription : response. text , filePath : audioFilePath, fileSize : stats. size }; } catch (error) { console . error ( 'Transcription error:' , error); return { success : false , error : error. message , filePath : audioFilePath }; } } 3. Post-Processing Transcriptions function cleanTranscription ( text ) { // Remove excessive whitespace text = text. replace ( /\s+/g , ' ' ). trim (); // Capitalize first letter of sentences text = text. replace ( /(^\w|[.!?]\s+\w)/g , match => match. toUpperCase ()); // Remove filler words (optional) const fillers = [ 'um' , 'uh' , 'ah' , 'like' , 'you know' ]; const fillerPattern = new RegExp ( `\\b( ${fillers.join( '|' )} )\\b` , 'gi' ); text = text. replace (fillerPattern, '' ). replace ( /\s+/g , ' ' ); return text; } async function transcribeAndClean ( audioFilePath ) { const zai = await ZAI . create (); const audioFile = fs. readFileSync (audioFilePath); const base64Audio = audioFile. toString ( 'base64' ); const response = await zai. audio . asr . create ({ file_base64 : base64Audio
Agent 识别该技能的关键词,点击任意一个即可复制。

该技能未提供触发词。

下载的 .skill 包内含以下字段。
字段 说明
format格式标识(skill/v1)
skill_id技能唯一 ID
name技能名称
version版本号
description技能描述
category所属分类(数组)
trigger_words触发词列表
tags标签列表
source来源标识
source_url来源链接(本页地址)
exported_at导出时间(每次下载生成)
system_prompt系统提示词正文
model_config模型参数:provider / model / temperature / max_tokens / top_p
examples示例
install_guide各平台导入说明(Coze / Dify / Claude / 自定义框架)
同一份技能可按不同平台格式导出。
.skill 标准格式,含 system_prompt 与 model_config,导入任意 Agent 框架即可使用 下载
.skillpro 增强格式,额外含脚本 / 工具 / 依赖 / 钩子占位 下载
.json 纯 JSON 导出,只含 system_prompt 与模型参数 下载
Coze 带 frontmatter 的 Markdown,Coze 平台导入用 下载
Dify Dify DSL,创建应用后直接导入 下载

每日精选 Skill 推荐,免费送到你邮箱

输入邮箱,每天接收一个精选 AI Agent 技能推荐。完全免费,持续更新。

提交后我们会发送一封确认邮件,点击邮件里的链接才会开始收信。

完全免费,取消任意时间。我们不会发送垃圾邮件。