IAHispano / Applio

A simple, high-quality voice conversion tool focused on ease of use and performance
https://applio.org
MIT License
1.78k stars 285 forks source link

Issues with Text-to-Speech Conversion Using Applio and f0_file Error #579

Closed moha6767 closed 3 months ago

moha6767 commented 3 months ago

Hello everyone,

I'm hoping you can help me with a problem I've encountered while trying to automate a process using a Python script I wrote. The goal is to create a script that automatically takes text files from one folder, converts them into audio files using Text-to-Speech, and then saves the completed audio files into a different folder. Unfortunately, I keep getting error messages when I run the script, and I'm getting quite frustrated because I can't seem to find a solution.

Here is the script I'm using:

import os
import subprocess
import webbrowser
import time
from gradio_client import Client

# Create Applio API Client
client = Client("http://127.0.0.1:6969/")

# Folder paths
input_folder = r"C:\Users\..\Desktop\Output Scripts"
output_folder = r"C:\Users\…\Desktop\Output Audio"

# Text-to-Speech function
def text_to_speech(text, voice_name, output_path):
    """Converts a text file to an audio file."""
    try:
        # Send API request to /run_tts_script (with pth_path and index_path)
        result = client.predict(
            tts_text=text,
            tts_voice=voice_name,
            output_tts_path=output_path,
            pth_path=r"C:\\\\Users\\\\…\\\\Desktop\\\\Applio-3.2.2\\\\logs\\\\kleiner_e350\\\\kleiner_e350.pth",  # Pth file
            index_path=r"C:\\\\Users\\\\…\\\\Desktop\\\\Applio-3.2.2\\\\logs\\\\v2.index\\\\added_IVF1346_Flat_nprobe_1_v2.index",  # Index file
            api_name="/run_tts_script",
        )
        print(f"Audio file '{output_path}' successfully created: {result}")

    except Exception as e:
        print(f"Error converting '{text}': {e}")

# Process scripts
for filename in os.listdir(input_folder):
    if filename.lower().endswith(".txt"):
        script_path = os.path.join(input_folder, filename)
        basename = os.path.splitext(filename)[0]
        audio_path = os.path.join(output_folder, f"{basename}.wav")
        # Convert text to speech
        text_to_speech(script_path, "de-DE-KatjaNeural", audio_path)

print("All scripts processed!")

However, I keep getting the following error message when I run the script:

Error converting 'path/to/textfile.txt': No value provided for required argument: f0_file

I've tried adjusting various parts of the script, but I keep running into the same issue. It seems like the f0_file argument is missing a value, but I'm not sure how to configure it correctly or where exactly the problem lies.

Has anyone here had experience with similar Text-to-Speech scripts or using Applio? I would greatly appreciate any help or tips on how to resolve this issue.

If it's relevant: I'm running the script locally on my computer and have embedded all the necessary paths in the code. I can provide more details about the setup or code if that would help narrow down the problem.

Thanks in advance for your support!

Best regards

blaisewf commented 3 months ago

f0_file=None

moha6767 commented 3 months ago

f0_file=None

Please tell me 1:1 what i have to do because i don’t know anything about python i am literally lost…. i would appreciate that really much.

blaisewf commented 3 months ago

Using Gradio as a CLI is horrible, Applio is not designed for it. Try this https://github.com/blaisewf/rvc-cli/

moha6767 commented 3 months ago

also RVC doesn’t work…

I've written a Python script that is supposed to convert text files into audio files using the RVC-CLI command for speech synthesis. The script runs without errors, and the CMD output confirms that the audio processing was successful. However, I can't find any audio files in the specified output folder.

Here's the code:

import subprocess
import os

def run_rvc_cli(text, output_tts_path, output_rvc_path, model_path, index_path, tts_voice="es-ES"):
    """Executes the RVC-CLI command for speech synthesis."""
    command = [
        r"C:\Users\...\AppData\Local\Programs\Python\Python38\python.exe",
        r"C:\Users\...\Desktop\rvc-cli-1.2.3\rvc_cli.py",
        "tts",
        "--tts_text", f'"{text.replace("'", "’")}"',
        "--tts_voice", tts_voice,
        "--output_tts_path", output_tts_path,
        "--output_rvc_path", output_rvc_path,
        "--pth_path", model_path,
        "--index_path", index_path
    ]

    try:
        subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
        print(f"TTS and RVC successfully executed. Audio file: {output_rvc_path}")
    except subprocess.CalledProcessError as e:
        print(f"Error executing RVC-CLI: {e.stderr}")

def main():
    model_path = r"C:\Users\...\Desktop\rvc-cli-1.2.3\logs\kleiner_e350\kleiner_e350.pth"
    index_path = r"C:\Users\...\Desktop\rvc-cli-1.2.3\logs\v2.index\added_IVF1346_Flat_nprobe_1_v2.index"
    output_directory = r"C:\Users\...\Desktop\Output Audio"
    input_directory = r"C:\Users\...\Desktop\Output Scripts"

    # Create the output directory if it doesn't exist
    os.makedirs(output_directory, exist_ok=True)

    # Read all text files from the input directory
    text_files = [f for f in os.listdir(input_directory) if f.endswith('.txt')]

    for i, text_file in enumerate(text_files):
        with open(os.path.join(input_directory, text_file), 'r', encoding='utf-8') as file:
            text = file.read()

        output_tts_file = os.path.join(output_directory, f"tts_output_{i}.wav")  # Temporary TTS file
        output_rvc_file = os.path.join(output_directory, f"rvc_output_{i}.wav")

        # Convert text to string and escape quotation marks
        escaped_text = f'"{text.replace("'", "’")}"'

        run_rvc_cli(escaped_text, output_tts_file, output_rvc_file, model_path, index_path)
        print(f"TTS and RVC for file {text_file} completed: {output_rvc_file}")

if __name__ == "__main__":
    main()

CMD indicates that the script was successfully executed and that the audio files were created. However, the files are not found in the target folder.