Replies: 3 comments
-
|
Something like this: srttotts.py |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Yes sir 😀 that what's I need ,thankyou.
…On Tue, Nov 19, 2024, 9:36 PM erew123 ***@***.***> wrote:
Something like this:
image.png (view on web)
<https://github.com/user-attachments/assets/1eae3323-4e16-4d6f-80df-b335dd640baa>
srttotts.py
import requests
import os
import re
import sys
# Try importing pysrt; install it if missing
try:
import pysrt
except ImportError:
print("pysrt not found. Installing it now...")
os.system(f"{sys.executable} -m pip install pysrt")
import pysrt
# Configuration for TTS API
API_URL = "http://127.0.0.1:7851/api/tts-generate" # Replace with actual IP and port
CHARACTER_VOICE = "female_01.wav" # Replace with the desired character voice file
LANGUAGE = "en" # Replace with the desired language
def parse_srt(file_path):
"""Parse an SRT file and return a list of subtitle texts."""
subs = pysrt.open(file_path)
return [sub.text for sub in subs]
def sanitize_filename(filename):
"""Sanitize filename to remove special characters, spaces, and extensions."""
# Remove all non-alphanumeric characters except underscores
sanitized = re.sub(r'[^A-Za-z0-9_]', '', filename)
return sanitized
def generate_tts(segment, output_file):
"""Send a TTS generation request to the API."""
payload = {
"text_input": segment,
"text_filtering": "standard",
"character_voice_gen": CHARACTER_VOICE,
"narrator_enabled": "false", # Change to "true" if narrator is used
"narrator_voice_gen": "male_01.wav",
"text_not_inside": "character",
"language": LANGUAGE,
"output_file_name": output_file,
"output_file_timestamp": "false",
"autoplay": "false",
}
response = requests.post(API_URL, data=payload)
if response.status_code == 200:
result = response.json()
if result["status"] == "generate-success":
print(f"TTS generated for segment: {output_file}.wav")
else:
print(f"Failed to generate TTS for {output_file}.wav: {result}")
else:
print(f"API Error {response.status_code}: {response.text}")
def process_srt_to_tts(srt_path):
"""Process the SRT file and generate TTS files."""
# Parse the SRT file
segments = parse_srt(srt_path)
# Extract the base name of the SRT file without extension
base_name = os.path.splitext(os.path.basename(srt_path))[0]
sanitized_base_name = sanitize_filename(base_name)
# Generate TTS for each segment
for i, segment in enumerate(segments, start=1):
# Create output file name with SRT base name as prefix
output_file = f"{sanitized_base_name}_{i:06d}" # Format as 'myfile_000001', 'myfile_000002', etc.
generate_tts(segment, output_file)
if __name__ == "__main__":
# Check if the script is called with a command-line argument
if len(sys.argv) < 2:
print("Usage: python script.py <path_to_srt_file>")
sys.exit(1)
# Get the SRT file path from the command-line arguments
SRT_FILE_PATH = sys.argv[1]
# Check if the file exists
if not os.path.exists(SRT_FILE_PATH):
print(f"Error: File '{SRT_FILE_PATH}' not found.")
sys.exit(1)
# Process the SRT file
process_srt_to_tts(SRT_FILE_PATH)
—
Reply to this email directly, view it on GitHub
<#412 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AYOWA4SONJFEOGSLBC4MB5T2BNOXHAVCNFSM6AAAAABSCNCNOOVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCMZQG44DEOA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
-
|
I would like to see this section in the web-UI for dubbing subtitles, if possible. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
-
I have an SRT file with n number of segments and I want to generate TTS of each segments separately and save it as 1.wav 2.wav to n.wav how can I call alltalktts api.
Beta Was this translation helpful? Give feedback.
All reactions