tts-repeating.rb
is a Ruby script designed for English repetition practice. It takes a text file, splits it into individual sentences, and generates corresponding audio files in MP3 format using Text-to-Speech (TTS). This allows users to practice their pronunciation and listening skills sentence by sentence.
OpenAI API Key: Set your OpenAI API key in a .env
file in the following format:
OPENAI_API_KEY=your_openai_api_key
- Clone or download the script.
- Install required Ruby gems using
bundle
command:$ bundle
- Create a
.env
file in the project directory and add your OpenAI API key.
Run the script with the following command:
ruby tts-repeating.rb [options]
-f FILE
: Specify the input text file.- Example:
-f input.txt
- Example:
-o OUTPUT
: Specify the output directory.- Default: The current directory.
- Example:
-o out_dir
-p PREFIX
: Set a prefix for output audio files.- Default: Current timestamp (e.g.,
202412051430
). - Example:
-p my_audio
- Default: Current timestamp (e.g.,
-v VOICE
: Choose a voice for the TTS output. Available voices:alloy
,echo
,fable
,onyx
,nova
,shimmer
- Example:
-v shimmer
--no-segmentation
: Disable sentence segmentation and treat the entire text as a single sentence.-h
: Display help information.
To process a file named sample.txt
with the shimmer
voice and a custom prefix:
ruby tts-repeating.rb -f sample.txt -p practice -v shimmer
Output:
- MP3 files named
practice-01.mp3
,practice-02.mp3
, etc.
Output files will be generated in the script's directory.
This script is open-source and can be used or modified under the terms of the MIT License.