Skip to content

anbeime/skill / skills/video-creation-collaborator/video-creation-collaborator

video-creation-collaborator

Verified

内容创作者与自媒体创作者在制作短视频时,若遇生图畸形、合成瑕疵或协同混乱,当需规范化多智能体流程时必用此技能。一键调度11个AI智能体,自动完成文案、分镜、音视频到视频合成的5阶段闭环,前置质检拦截瑕疵,高效产出统一可控的高质量短视频。

scripts/audio_generator.py

View on GitHub
#!/usr/bin/env python3
"""
音频生成脚本
调用TTS接口,根据文本生成旁白/配音音频
"""

import os
import sys
from typing import Dict, Any, List
import json


def generate_audio(narration_data: Dict[str, Any],
                   output_dir: str = "./output/audio",
                   voice_style: str = "male_young") -> Dict[str, Any]:
    """
    根据旁白数据生成音频

    参数:
        narration_data: 旁白数据,包含文本和音色要求
        output_dir: 输出目录
        voice_style: 音色风格

    返回:
        生成结果字典,包含成功/失败信息
    """
    # 确保输出目录存在
    os.makedirs(output_dir, exist_ok=True)

    results = {
        'success': True,
        'total_segments': 0,
        'generated': 0,
        'failed': 0,
        'audios': [],
        'errors': []
    }

    try:
        # 获取旁白段落数据
        segments = narration_data.get('segments', [])
        results['total_segments'] = len(segments)

        if not segments:
            raise ValueError("旁白数据中没有段落")

        # 遍历每个段落,生成音频
        for i, segment in enumerate(segments, start=1):
            segment_id = segment.get('segment_id', f'S{i:02d}')
            text = segment.get('text', '')
            voice = segment.get('voice', voice_style)
            speed = segment.get('speed', 1.0)
            emotion = segment.get('emotion', 'neutral')

            if not text:
                raise ValueError(f"段落{segment_id}缺少文本")

            # 生成文件名
            filename = f"narration_{segment_id}.wav"
            filepath = os.path.join(output_dir, filename)

            # 调用TTS接口生成音频
            audio_url = generate_single_audio(
                text=text,
                voice=voice,
                speed=speed,
                emotion=emotion
            )

            if audio_url:
                # 下载音频
                success = download_audio(audio_url, filepath)
                if success:
                    results['generated'] += 1
                    results['audios'].append({
                        'segment_id': segment_id,
                        'filename': filename,
                        'filepath': filepath,
                        'duration': segment.get('duration', 0),
                        'status': 'success'
                    })
                else:
                    results['failed'] += 1
                    results['audios'].append({
                        'segment_id': segment_id,
                        'filename': filename,
                        'status': 'failed',
                        'error': '下载失败'
                    })
            else:
                results['failed'] += 1
                results['audios'].append({
                    'segment_id': segment_id,
                    'filename': filename,
                    'status': 'failed',
                    'error': '生成失败'
                })

    except Exception as e:
        results['success'] = False
        results['errors'].append(str(e))

    return results


def generate_single_audio(text: str,
                          voice: str = "male_young",
                          speed: float = 1.0,
                          emotion: str = "neutral") -> str:
    """
    生成单段音频

    参数:
        text: 文本内容
        voice: 音色
        speed: 语速
        emotion: 情绪

    返回:
        音频URL或空字符串
    """
    # TODO: 实现TTS接口调用
    # 这里需要根据实际使用的TTS接口进行实现
    # 例如: Azure Speech API, Google Cloud Text-to-Speech, 百度语音合成等

    # 示例: 使用Azure Speech API
    # import azure.cognitiveservices.speech as speechsdk
    # speech_config = speechsdk.SpeechConfig(subscription="YOUR_KEY", region="YOUR_REGION")
    # speech_config.speech_synthesis_voice_name = f"zh-CN-{voice}"
    # audio_config = speechsdk.audio.AudioOutputConfig(filename=filepath)
    # synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
    # result = synthesizer.speak_text_async(text).get()
    # return audio_config.filename if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted else ""

    # 临时返回空字符串,需要替换为实际实现
    print(f"生成音频: {text}")
    print(f"音色: {voice}, 语速: {speed}, 情绪: {emotion}")
    return ""


def download_audio(audio_url: str, filepath: str) -> bool:
    """
    下载音频

    参数:
        audio_url: 音频URL
        filepath: 保存路径

    返回:
        是否成功
    """
    # TODO: 实现音频下载
    # import requests
    # response = requests.get(audio_url)
    # with open(filepath, 'wb') as f:
    #     f.write(response.content)
    # return True

    # 临时返回True,需要替换为实际实现
    print(f"下载音频: {audio_url} -> {filepath}")
    return True


def merge_audio_with_background(narration_files: List[str],
                                background_music: str,
                                output_file: str,
                                narration_volume: float = 0.5,
                                background_volume: float = 0.3) -> bool:
    """
    将旁白与背景音乐混合

    参数:
        narration_files: 旁白文件列表
        background_music: 背景音乐文件
        output_file: 输出文件
        narration_volume: 旁白音量(0-1)
        background_volume: 背景音乐音量(0-1)

    返回:
        是否成功
    """
    # TODO: 实现音频混合
    # 需要使用pydub或类似库

    # 临时返回True,需要替换为实际实现
    print(f"混合音频: {len(narration_files)}个旁白 + 背景音乐 -> {output_file}")
    print(f"旁白音量: {narration_volume}, 背景音乐音量: {background_volume}")
    return True


def print_generation_report(results: Dict[str, Any]):
    """
    打印生成报告

    参数:
        results: generate_audio() 返回的结果
    """
    if not results['success']:
        print(f"❌ 生成失败: {results.get('errors', [])}")
        return

    print("=" * 60)
    print("音频生成报告")
    print("=" * 60)
    print(f"总段落数: {results['total_segments']}")
    print(f"生成成功: {results['generated']}")
    print(f"生成失败: {results['failed']}")
    print()

    if results['audios']:
        print("生成详情:")
        for audio in results['audios']:
            status = "✅" if audio['status'] == 'success' else "❌"
            duration = audio.get('duration', 0)
            print(f"  {status} {audio['segment_id']}: {audio['filename']} ({duration}秒)")
            if audio['status'] == 'failed':
                print(f"      错误: {audio.get('error', '未知错误')}")


if __name__ == '__main__':
    import argparse

    parser = argparse.ArgumentParser(description='音频生成脚本')
    parser.add_argument('--narration', type=str, required=True,
                       help='旁白数据JSON文件路径')
    parser.add_argument('--output-dir', type=str, default="./output/audio",
                       help='输出目录')
    parser.add_argument('--voice-style', type=str, default="male_young",
                       help='音色风格')

    args = parser.parse_args()

    # 读取旁白数据
    with open(args.narration, 'r', encoding='utf-8') as f:
        narration_data = json.load(f)

    # 生成音频
    results = generate_audio(
        narration_data=narration_data,
        output_dir=args.output_dir,
        voice_style=args.voice_style
    )

    # 打印报告
    print_generation_report(results)

    # 返回状态码
    sys.exit(0 if results['success'] and results['failed'] == 0 else 1)
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall