las_audio_convert)
Convert audio files on TOS to the specified format (wav/mp3/flac), and you can adjust the sample rate, number of channels, etc. by passing ffmpeg parameters via extra_params .
Design Pattern
This skill mainly adopts:
- Tool Wrapper: Encapsulates
lasutilCLI calls - Pipeline: Includes a sequential workflow from Step 0 → Step N
Core API and Configuration
- Operator ID:
las_audio_convert - API: Synchronous (
process) - Environment Variables:
LAS_API_KEY(Required)
For detailed parameters and interface definitions, see references/api.md。
Gotchas
- Key Security: If the chat box blocks the key, ask the user to create
env.shin the current directory and writeexport LAS_API_KEY="..."into it, and the SDK will read it automatically. - Disclaimer: When giving the final reply, it must include: "本方式的计费均为预估计费,与实际费用有差距,实际费用以运行后火山产生的账单为准。计费说明请参考 Volcengine LAS Pricing。", and it is forbidden to use the words "actual cost" to describe the estimated price.
Workflow (Strictly Follow the Steps)
Copy this checklist and track progress:
执行进度:
- [ ] Step 0: 前置检查
- [ ] Step 1: 初始化与准备
- [ ] Step 2: 预估价格
- [ ] Step 3: 执行/提交任务
- [ ] Step 4: 结果呈现
Step 0: Pre-check (⚠️ Must be completed in the first round of dialogue)
After accepting the user's task,do not start execution immediately, and you must first perform the following environment checks:
- Check
LAS_API_KEYandLAS_REGION: Confirm whether they are already configured in the environment variables or.env.- If not, you must immediately ask the user for them (hint:
LAS_REGIONis commonlycn-beijing)。 - Note:
LAS_REGIONmust be completely consistent with the region where your API Key and TOS Bucket are located. If the user switches Region midway, you must remind the user that their TOS Bucket also needs to be changed accordingly; otherwise, it will cause permission exceptions or upload failures.
- If not, you must immediately ask the user for them (hint:
- Check input path:
- If what the user requests to process is alocal file, it needs to first be uploaded to TOS via the File API (only
LAS_API_KEY, no additional TOS credentials are needed). - If the operator'soutput resultis stored on TOS and the user needs to download it back locally, then
VOLCENGINE_ACCESS_KEYandVOLCENGINE_SECRET_KEYare needed. For the scenario whereonly the input file needs to be uploaded, TOS credentials areno longer required。
- If what the user requests to process is alocal file, it needs to first be uploaded to TOS via the File API (only
- After confirmation is correct: only then can you proceed to the next step.
Step 1: Initialization and Preparation
Environment Initialization (Agent must do):
# 执行统一的环境初始化与更新脚本(会自动创建/激活虚拟环境,并检查更新)
source "$(dirname "$0")/scripts/env_init.sh" las_audio_convert
workdir=$LAS_WORKDIR
If network issues cause the update to fail, the script will skip the check and continue execution using the locally installed SDK.
- When processing local files: First check the format and duration locally, estimate the price, and upload only after the user confirms:
Calculate the estimated price and wait for user confirmation, then execute the upload:# 提前检查容器格式(避免参数错误) ./scripts/check_format.sh <local_path> # 本地使用 ffprobe 获取时长(无需上传即可预估价格) duration_sec=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:noprint_section=1 <local_path>)
After a successful upload, JSON is returned; take the# 用户确认后,上传到 TOS lasutil file-upload <local_path>tos_uri(formattos://bucket/key) and pass it to the operator as the input path.
Step 2: Estimate Price (⚠️ Must obtain user confirmation)
- Read references/prices.md to get the latest billing standard.
- Prefer obtaining the duration locally(to avoid unnecessary uploads):
If ffprobe fails, then use lasutil to obtain it remotely:# 使用 ffprobe 本地获取 duration_sec=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:noprint_section=1 <local_path>)lasutil media-duration <input_audio_url> - Calculate the total price based on the duration and model unit price,inform the user of the billing unit price together with the estimated total price and forcibly pause execution, and explicitly wait for the user's reply to confirm. Before the user explicitly replies with an approval instruction such as "continue" or "confirm",it is absolutely forbiddento proceed to the next step (execute/submit the task). Note: the estimate is for reference only; the actual amount is subject to the Volcengine bill. For billing details, please refer to Volcengine LAS Pricing。
Step 3: Execute the conversion (Process)
Construct the basic data.json(only required fields are needed; advanced usage can add "extra_params": ["-ar", "44100", "-ac", "1"]):
{
"input_path": "<presigned_url>",
"output_path": "tos://bucket/output.wav",
"output_format": "wav"
}
Execute the command:
data=$(cat "$workdir/data.json")
lasutil process las_audio_convert "$data" > "$workdir/result.json"
Result presentation
Use the script to automatically generate the result display (automatically includes the billing statement):
./scripts/generate_result.md.sh $workdir/result.json <estimated_price>
The generated content includes:
- Task information card
- Automatically generate the conversion result table
- Automatically include the billing statement ✅
Manual extraction method:
jq '[.data.audios[] | {
input: (.input_path | split("/") | last),
output: .output_path,
duration: "\(.duration)s",
status: .status
}]' result.json
If status is failed, mark it as ❌ and prompt the user to check the input format.
Review criteria
After execution is complete, the Agent should self-check:
- Whether the environment variables are correctly configured
- Whether the input files were successfully uploaded
- Whether the output results are correctly presented to the user
- Whether the billing statement is included