Repository: Blaizzy/mlx-audio
File: mlx_audio/tts/generate.py (Python)

Code before:
    parser.add_argument("--lang_code", type=str, default="a", help="Language code")
    parser.add_argument(
        "--file_prefix", type=str, default="audio", help="Output file name prefix"
    )
    parser.add_argument("--verbose", action="store_false", help="Print verbose output")
    parser.add_argument(
        "--join_audio", action="store_true", help="Join all audio files into one"
    )
    parser.add_argument("--play", action="store_true", help="Play the output audio")
    args = parser.parse_args()

    if args.text is None:
        if not sys.stdin.isatty():
            args.text = sys.stdin.read().strip()
        else:
            print("Please enter the text to generate:")
            args.text = input("> ").strip()

    return args


def main():
    args = parse_args()
    try:
        if args.play:
            player = AudioPlayer()

        model = load_model(model_path=args.model)
        print(
            f"\n\033[94mModel:\033[0m {args.model}\n"
            f"\033[94mText:\033[0m {args.text}\n"
            f"\033[94mVoice:\033[0m {args.voice}\n"
            f"\033[94mSpeed:\033[0m {args.speed}x\n"
            f"\033[94mLanguage:\033[0m {args.lang_code}"
        )
        print("==========")
        results = model.generate(
            text=args.text,
            voice=args.voice,
            speed=args.speed,
            lang_code=args.lang_code,
            verbose=True,
        )
        print(
            f"\033[92mAudio generated successfully, saving to\033[0m {args.file_prefix}!"
        )

        audio_list = []
        for i, result in enumerate(results):
            if args.join_audio:
                audio_list.append(result.audio)

Review comment (suggestion):
```suggestion
        player = AudioPlayer() if args.play else None
```

Code after:
    parser.add_argument("--lang_code", type=str, default="a", help="Language code")
    parser.add_argument(
        "--file_prefix", type=str, default="audio", help="Output file name prefix"
    )
    parser.add_argument("--verbose", action="store_false", help="Print verbose output")
    parser.add_argument(
        "--join_audio", action="store_true", help="Join all audio files into one"
    )
    parser.add_argument("--play", action="store_true", help="Play the output audio")
    args = parser.parse_args()

    if args.text is None:
        if not sys.stdin.isatty():
            args.text = sys.stdin.read().strip()
        else:
            print("Please enter the text to generate:")
            args.text = input("> ").strip()

    return args


def main():
    args = parse_args()
    try:
        player = AudioPlayer() if args.play else None

        model = load_model(model_path=args.model)
        print(
            f"\n\033[94mModel:\033[0m {args.model}\n"
            f"\033[94mText:\033[0m {args.text}\n"
            f"\033[94mVoice:\033[0m {args.voice}\n"
            f"\033[94mSpeed:\033[0m {args.speed}x\n"
            f"\033[94mLanguage:\033[0m {args.lang_code}"
        )
        print("==========")
        results = model.generate(
            text=args.text,
            voice=args.voice,
            speed=args.speed,
            lang_code=args.lang_code,
            verbose=True,
        )
        print(
            f"\033[92mAudio generated successfully, saving to\033[0m {args.file_prefix}!"
        )

        audio_list = []
        for i, result in enumerate(results):
            if args.play:
                player.queue_audio(result.audio)
            if args.join_audio: