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

Code before:
        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)
            elif args.play:
                player.queue_audio(result.audio)
            else:
                sf.write(f"{args.file_prefix}_{i:03d}.wav", result.audio, 24000)

            if args.verbose:
                print("==========")
                print(f"Duration:              {result.audio_duration}")
                print(
                    f"Samples/sec:           {result.audio_samples['samples-per-sec']:.1f}"
                )
                print(
                    f"Prompt:                {result.token_count} tokens, {result.prompt['tokens-per-sec']:.1f} tokens-per-sec"
                )
                print(
                    f"Audio:                 {result.audio_samples['samples']} samples, {result.audio_samples['samples-per-sec']:.1f} samples-per-sec"
                )
                print(f"Real-time factor:      {result.real_time_factor:.2f}x")
                print(f"Processing time:       {result.processing_time_seconds:.2f}s")
                print(f"Peak memory usage:     {result.peak_memory_usage:.2f}GB")

        if args.join_audio and not args.play:
            print(f"Joining {len(audio_list)} audio files")
            audio = mx.concatenate(audio_list, axis=0)
            sf.write(f"{args.file_prefix}.wav", audio, 24000)

        if args.play:

Review comment (suggestion):
```suggestion
            if args.play:
                player.queue_audio(result.audio)
            if args.join_audio:
                audio_list.append(result.audio)
```

Code after:
        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:
                audio_list.append(result.audio)
            else:
                sf.write(f"{args.file_prefix}_{i:03d}.wav", result.audio, 24000)

            if args.verbose:
                print("==========")
                print(f"Duration:              {result.audio_duration}")
                print(
                    f"Samples/sec:           {result.audio_samples['samples-per-sec']:.1f}"
                )
                print(
                    f"Prompt:                {result.token_count} tokens, {result.prompt['tokens-per-sec']:.1f} tokens-per-sec"
                )
                print(
                    f"Audio:                 {result.audio_samples['samples']} samples, {result.audio_samples['samples-per-sec']:.1f} samples-per-sec"
                )
                print(f"Real-time factor:      {result.real_time_factor:.2f}x")
                print(f"Processing time:       {result.processing_time_seconds:.2f}s")
                print(f"Peak memory usage:     {result.peak_memory_usage:.2f}GB")

        if args.join_audio:
            print(f"Joining {len(audio_list)} audio files")
            audio = mx.concatenate(audio_list, axis=0)
            sf.write(f"{args.file_prefix}.wav", audio, 24000)

        if args.play:
            player.wait_for_drain()