Update app.py
Browse files
app.py
CHANGED
@@ -104,16 +104,14 @@ def decode_tokens(token_file):
|
|
104 |
if isinstance(waveform, torch.Tensor):
|
105 |
waveform = waveform.cpu().numpy()
|
106 |
|
107 |
-
#
|
108 |
-
|
109 |
-
|
110 |
-
output_buffer.seek(0)
|
111 |
|
112 |
-
|
113 |
-
if output_buffer.getbuffer().nbytes == 0:
|
114 |
-
return None, "Error: Failed to generate audio"
|
115 |
|
116 |
-
|
|
|
117 |
except Exception as e:
|
118 |
print(f"Decoding error: {str(e)}")
|
119 |
return None, f"Error decoding tokens: {str(e)}"
|
@@ -155,16 +153,14 @@ def process_both(audio_path):
|
|
155 |
if isinstance(waveform, torch.Tensor):
|
156 |
waveform = waveform.cpu().numpy()
|
157 |
|
158 |
-
#
|
159 |
-
|
160 |
-
|
161 |
-
output_buffer.seek(0)
|
162 |
|
163 |
-
|
164 |
-
if output_buffer.getbuffer().nbytes == 0:
|
165 |
-
return None, "Error: Failed to generate audio"
|
166 |
|
167 |
-
|
|
|
168 |
except Exception as e:
|
169 |
print(f"Processing error: {str(e)}")
|
170 |
return None, f"Error processing audio: {str(e)}"
|
|
|
104 |
if isinstance(waveform, torch.Tensor):
|
105 |
waveform = waveform.cpu().numpy()
|
106 |
|
107 |
+
# Extract audio data - this should be a numpy array
|
108 |
+
audio_data = waveform[0, 0] # Shape should be [time]
|
109 |
+
sample_rate = 32000
|
|
|
110 |
|
111 |
+
print(f"Audio data shape: {audio_data.shape}, dtype: {audio_data.dtype}")
|
|
|
|
|
112 |
|
113 |
+
# Return in Gradio Audio compatible format: (sample_rate, audio_data)
|
114 |
+
return (sample_rate, audio_data), f"Decoded {tokens.shape[1]} tokens to audio"
|
115 |
except Exception as e:
|
116 |
print(f"Decoding error: {str(e)}")
|
117 |
return None, f"Error decoding tokens: {str(e)}"
|
|
|
153 |
if isinstance(waveform, torch.Tensor):
|
154 |
waveform = waveform.cpu().numpy()
|
155 |
|
156 |
+
# Extract audio data - this should be a numpy array
|
157 |
+
audio_data = waveform[0, 0] # Shape should be [time]
|
158 |
+
sample_rate = 32000
|
|
|
159 |
|
160 |
+
print(f"Audio data shape: {audio_data.shape}, dtype: {audio_data.dtype}")
|
|
|
|
|
161 |
|
162 |
+
# Return in Gradio Audio compatible format: (sample_rate, audio_data)
|
163 |
+
return (sample_rate, audio_data), f"Encoded to {tokens.shape[1]} tokens\nDecoded {tokens.shape[1]} tokens to audio"
|
164 |
except Exception as e:
|
165 |
print(f"Processing error: {str(e)}")
|
166 |
return None, f"Error processing audio: {str(e)}"
|