drewThomasson commited on
Commit
6879295
·
verified ·
1 Parent(s): 8c245c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -8
app.py CHANGED
@@ -10,12 +10,18 @@ tts = TTS().from_pretrained("AstraMindAI/xttsv2", gpt_model="AstraMindAI/xtts2-g
10
 
11
  # Function to generate speech with enhancement
12
  def generate_speech_with_enhancement(text, speaker_audio):
13
- start_time = time.time() # Start timing
 
14
 
 
 
15
  # Read the speaker audio file
16
- with open(speaker_audio, "rb") as f:
17
- audio_data = f.read()
18
-
 
 
 
19
  # Create an instance of AudioPreprocessingConfig for enhancement
20
  audio_config = AudioPreprocessingConfig(
21
  normalize=True,
@@ -47,12 +53,18 @@ def generate_speech_with_enhancement(text, speaker_audio):
47
 
48
  # Function to generate speech without enhancement
49
  def generate_speech_without_enhancement(text, speaker_audio):
50
- start_time = time.time() # Start timing
 
51
 
 
 
52
  # Read the speaker audio file
53
- with open(speaker_audio, "rb") as f:
54
- audio_data = f.read()
55
-
 
 
 
56
  # Create the TTS request without enhancement
57
  request = TTSRequest(
58
  text=text,
 
10
 
11
  # Function to generate speech with enhancement
12
  def generate_speech_with_enhancement(text, speaker_audio):
13
+ if not speaker_audio:
14
+ return None, "Error: No speaker audio provided."
15
 
16
+ start_time = time.time() # Start timing
17
+
18
  # Read the speaker audio file
19
+ try:
20
+ with open(speaker_audio, "rb") as f:
21
+ audio_data = f.read()
22
+ except Exception as e:
23
+ return None, f"Error reading speaker audio: {e}"
24
+
25
  # Create an instance of AudioPreprocessingConfig for enhancement
26
  audio_config = AudioPreprocessingConfig(
27
  normalize=True,
 
53
 
54
  # Function to generate speech without enhancement
55
  def generate_speech_without_enhancement(text, speaker_audio):
56
+ if not speaker_audio:
57
+ return None, "Error: No speaker audio provided."
58
 
59
+ start_time = time.time() # Start timing
60
+
61
  # Read the speaker audio file
62
+ try:
63
+ with open(speaker_audio, "rb") as f:
64
+ audio_data = f.read()
65
+ except Exception as e:
66
+ return None, f"Error reading speaker audio: {e}"
67
+
68
  # Create the TTS request without enhancement
69
  request = TTSRequest(
70
  text=text,