CoolFace
Apppublic

MatteoFasulo/Whisper-TikTok-Demo

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
3likes
arg_parser.py99 linesDownload Raw Back to src
1import argparse2import sys3 4# voice_manager.py5from src.voice_manager import VoicesManager6 7import msg8from utils import rgb_to_bgr9 10 11async def parse_args():12    parser = argparse.ArgumentParser()13    parser.add_argument("--model", default="small", help="Model to use",14                        choices=["tiny", "base", "small", "medium", "large"], type=str)15    parser.add_argument("--non_english", action='store_true',16                        help="Don't use the english model.")17    parser.add_argument("--url", metavar='U', default="https://www.youtube.com/watch?v=intRX7BRA90",18                        help="Youtube URL to download as background video.", type=str)19    parser.add_argument("--tts", default="en-US-ChristopherNeural",20                        help="Voice to use for TTS", type=str)21    parser.add_argument(22        "--list-voices", help="Use `edge-tts --list-voices` to list all voices", action='help')23    parser.add_argument("--random_voice", action='store_true',24                        help="Random voice for TTS", default=False)25    parser.add_argument("--gender", choices=["Male", "Female"],26                        help="Gender of the random TTS voice", type=str)27    parser.add_argument(28        "--language", help="Language of the random TTS voice for example: en-US", type=str)29    parser.add_argument("--sub_format",30                        help="Subtitle format", choices=["u", "i", "b"], default="b", type=str)31    parser.add_argument("--sub_position",32                        help="Subtitle position", choices=[i for i in range(1, 10)], default=5, type=int)33    parser.add_argument("--font", help="Subtitle font",34                        default="Lexend Bold", type=str)35    parser.add_argument("--font_color", help="Subtitle font color in hex format: FFF000",36                        default="FFF000", type=str)37    parser.add_argument(38        "--font_size", help="Subtitle font size", default=21, type=int)39    parser.add_argument('--max_characters', default=38,40                        type=int, help='Max characters per line')41    parser.add_argument('--max_words', default=2, type=int,42                        help='Max words per segment')43    parser.add_argument("--upload_tiktok", help="Upload to TikTok after creating the video",44                        action='store_true', default=False)45    parser.add_argument("-v", "--verbose", action='store_true',46                        help="Verbose")47    args = parser.parse_args()48 49    if args.random_voice:  # Random voice50        args.tts = None51        if not args.gender:52            print(53                f"{msg.ERROR}When using --random_voice, please specify both --gender and --language arguments.")54            sys.exit(1)55 56        elif not args.language:57            print(58                f"{msg.ERROR}When using --random_voice, please specify both --gender and --language arguments.")59            sys.exit(1)60 61        elif args.gender and args.language:62            # Check if voice is valid63            voices_manager_obj = await VoicesManager().create()64            voices = await VoicesManager().find(voices_manager_obj, args.gender, args.language)65            args.tts = voices['Name']66 67            # Check if language is english68            if not str(args.language).startswith('en'):69                args.non_english = True70 71    else:72        # Check if voice is valid73        voices = await VoicesManager().create()74        args.language = '-'.join(i for i in args.tts.split('-')[0:2])75        voices = voices.find(Locale=args.language)76        if len(voices) == 0:77            # Voice not found78            print(79                f"{msg.ERROR}Specified TTS voice not found. Use `edge-tts --list-voices` to list all voices.")80            sys.exit(1)81 82    # Extract language from TTS voice83    if args.tts:84        lang_prefix = args.tts.split('-')[0]85        if not lang_prefix.startswith('en'):86            args.non_english = True87 88    # Cast font color to lowercase89    args.font_color = args.font_color.lower()90 91    # Remove # from font color92    if args.font_color.startswith('#'):93        args.font_color = args.font_color[1:]94 95    # Convert font color from RGB to BGR96    args.font_color = rgb_to_bgr(args.font_color)97 98    return args99 
MatteoFasulo/Whisper-TikTok-Demo · CoolFace