hans00 commited on
Commit
216ef9a
·
unverified ·
1 Parent(s): 9f7398c

Tip error when create speaker failed

Browse files
Files changed (1) hide show
  1. app.py +18 -11
app.py CHANGED
@@ -104,13 +104,16 @@ def get_or_create_speaker(interface, audio_file):
104
 
105
  # Create new speaker profile
106
  print(f"🔄 Creating new speaker profile for {os.path.basename(audio_file)}")
107
- speaker = interface.create_speaker(audio_file, whisper_model="large-v3-turbo", whisper_device=device)
108
-
109
- # Cache the speaker profile
110
- speaker_cache[cache_key] = speaker
111
- print(f"💾 Cached speaker profile ({len(speaker_cache)} total cached)")
112
-
113
- return speaker
 
 
 
114
 
115
  @spaces.GPU
116
  def create_speaker_and_generate(model_name, audio_file, test_text: Optional[str] = None, temperature: float = 0.4):
@@ -123,10 +126,14 @@ def create_speaker_and_generate(model_name, audio_file, test_text: Optional[str]
123
  interface = get_interface(model_name)
124
 
125
  # Get or create speaker profile (with caching)
126
- speaker = get_or_create_speaker(interface, audio_file)
 
 
 
 
127
 
128
  # Convert speaker dict to formatted JSON
129
- speaker_json = json.dumps(speaker, indent=2, ensure_ascii=False)
130
 
131
  # Generate test audio if text is provided
132
  generated_audio = None
@@ -134,7 +141,7 @@ def create_speaker_and_generate(model_name, audio_file, test_text: Optional[str]
134
  output = interface.generate(
135
  config=outetts.GenerationConfig(
136
  text=test_text,
137
- speaker=speaker,
138
  sampler_config=outetts.SamplerConfig(
139
  temperature=temperature
140
  ),
@@ -162,7 +169,7 @@ demo = gr.Interface(
162
  info="Choose the model variant to use"
163
  ),
164
  gr.Audio(
165
- label="Upload Reference Audio",
166
  type="filepath",
167
  sources=["upload", "microphone"]
168
  ),
 
104
 
105
  # Create new speaker profile
106
  print(f"🔄 Creating new speaker profile for {os.path.basename(audio_file)}")
107
+ try:
108
+ speaker = interface.create_speaker(audio_file, whisper_model="large-v3-turbo", whisper_device=device)
109
+
110
+ # Cache the speaker profile
111
+ speaker_cache[cache_key] = speaker
112
+ print(f"💾 Cached speaker profile ({len(speaker_cache)} total cached)")
113
+
114
+ return speaker
115
+ except Exception as e:
116
+ return f"❌ Error creating speaker profile: {str(e)}"
117
 
118
  @spaces.GPU
119
  def create_speaker_and_generate(model_name, audio_file, test_text: Optional[str] = None, temperature: float = 0.4):
 
126
  interface = get_interface(model_name)
127
 
128
  # Get or create speaker profile (with caching)
129
+ speaker_result = get_or_create_speaker(interface, audio_file)
130
+
131
+ # Check if speaker_result is an error message
132
+ if isinstance(speaker_result, str) and speaker_result.startswith("❌"):
133
+ return speaker_result, None
134
 
135
  # Convert speaker dict to formatted JSON
136
+ speaker_json = json.dumps(speaker_result, indent=2, ensure_ascii=False)
137
 
138
  # Generate test audio if text is provided
139
  generated_audio = None
 
141
  output = interface.generate(
142
  config=outetts.GenerationConfig(
143
  text=test_text,
144
+ speaker=speaker_result,
145
  sampler_config=outetts.SamplerConfig(
146
  temperature=temperature
147
  ),
 
169
  info="Choose the model variant to use"
170
  ),
171
  gr.Audio(
172
+ label="Upload Reference Audio (Max 20 seconds)",
173
  type="filepath",
174
  sources=["upload", "microphone"]
175
  ),