├── .gitattributes ├── README.md ├── app.py ├── app2.py └── check.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MultiTTS 2 | ## Text-to-Speech Conversion using ElevenLabs API 3 | 4 | This script allows you to convert text files to speech using the ElevenLabs API. It reads text files from a specified input folder, generates speech using the API, and saves the resulting audio files in an output folder. 5 | 6 | ## Requirements 7 | 8 | - Python 3.x 9 | - ElevenLabs API key (sign up at [ElevenLabs website](https://beta.elevenlabs.io//)) 10 | 11 | ## Installation 12 | 13 | 1. Clone or download the script to your local machine. 14 | 2. Install the required Python packages by running the following command: 15 | 16 | ```shell 17 | pip install elevenlabs 18 | ``` 19 | 20 | ## Configuration 21 | 22 | Before running the script, you need to set up the following variables in the script: 23 | 24 | - `set_api_key("")`: Replace `` with your actual ElevenLabs API key. 25 | - `voice = "Your_Voice_id"`: Set `Your_Voice_id` to your preferred voice ID. You can find the available voice IDs in the ElevenLabs API documentation. 26 | - `model = "elevenlabs_monolingual_v1"`: Set `elevenlabs_monolingual_v1` to your preferred model. You can find the available models in the ElevenLabs API documentation. 27 | - `input_folder = "path/to/input/folder"`: Set `path/to/input/folder` to the path of the folder containing your input text files. 28 | - `output_folder = "path/to/output/folder"`: Set `path/to/output/folder` to the path where you want to save the output audio files. 29 | 30 | ## Usage 31 | 32 | 1. Place your text files in the input folder specified in the script. 33 | 2. Open a terminal or command prompt and navigate to the directory containing the script. 34 | 3. Run the following command to execute the script: 35 | 36 | ```shell 37 | python app.py 38 | ``` 39 | 40 | 41 | 4. The script will convert each text file in the input folder to speech using the ElevenLabs API and save the resulting audio files in the output folder. 42 | 5. Once the script has finished processing all the files, you will find the converted audio files in the output folder. 43 | 44 | ## Note 45 | 46 | - Ensure that you have a stable internet connection while running the script, as it requires access to the ElevenLabs API. 47 | - Make sure that the input and output folders exist before running the script. The script will not create the folders automatically. 48 | - The script uses the `.txt` extension to identify the input text files. Only files with the `.txt` extension will be processed. 49 | 50 | ## License 51 | 52 | This project is licensed under the terms of the MIT license. 53 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | import os 2 | import glob 3 | from elevenlabs import save, generate, set_api_key, voices 4 | 5 | set_api_key("") # replace with your actual API key 6 | 7 | voice = "Your_Voice_id" # Set your preferred voice 8 | model = "elevenlabs_monolingual_v1" #set your preferred model 9 | 10 | input_folder = "path/to/input/folder" # Enter the path to your folder 11 | output_folder = "path/to/output/folder" # Enter the path to output folder 12 | 13 | 14 | 15 | def text_to_speech(file_path, output_folder, voice): 16 | with open(file_path, 'r') as file: 17 | text = file.read() 18 | 19 | audio = generate(text=text, voice=voice) 20 | 21 | output_path = os.path.join(output_folder, os.path.basename(file_path).replace('.txt', '.mp3')) 22 | with open(output_path, "wb") as output: 23 | output.write(audio) 24 | 25 | return output_path 26 | 27 | def main(): 28 | 29 | os.makedirs(output_folder, exist_ok=True) 30 | 31 | txt_files = glob.glob(os.path.join(input_folder, '*.txt')) 32 | 33 | for txt_file in txt_files: 34 | text_to_speech(txt_file, output_folder, voice) 35 | 36 | if __name__ == "__main__": 37 | main() -------------------------------------------------------------------------------- /app2.py: -------------------------------------------------------------------------------- 1 | import os 2 | import glob 3 | from tqdm import tqdm 4 | from elevenlabs import save, generate, set_api_key, voices 5 | 6 | api_key = (input("Enter your API key: ")) 7 | set_api_key(api_key) 8 | voice = input("Enter your preferred voice: ") 9 | model = input("Enter your preferred model: ") 10 | input_folder = input("Enter the path to your input folder: ") 11 | output_folder = input("Enter the path to your output folder: ") 12 | 13 | def text_to_speech(file_path, output_folder, voice): 14 | with open(file_path, 'r') as file: 15 | text = file.read() 16 | 17 | audio = generate(text=text, voice=voice) 18 | 19 | output_path = os.path.join(output_folder, os.path.basename(file_path).replace('.txt', '.mp3')) 20 | with open(output_path, "wb") as output: 21 | output.write(audio) 22 | 23 | return output_path 24 | 25 | def main(): 26 | os.makedirs(output_folder, exist_ok=True) 27 | 28 | txt_files = glob.glob(os.path.join(input_folder, '*.txt')) 29 | 30 | with tqdm(total=len(txt_files), desc="Converting files") as pbar: 31 | for txt_file in txt_files: 32 | text_to_speech(txt_file, output_folder, voice) 33 | pbar.update(1) 34 | 35 | print("Done!") 36 | 37 | if __name__ == "__main__": 38 | main() -------------------------------------------------------------------------------- /check.py: -------------------------------------------------------------------------------- 1 | # Checks which voices are available for you and pritnts it into the console. 2 | 3 | from elevenlabs import set_api_key, Voices 4 | 5 | set_api_key("") # replace with your actual API key 6 | 7 | voices = Voices.from_api() 8 | print(voices[0]) 9 | print(voices) --------------------------------------------------------------------------------