Update app.py
Browse files
app.py
CHANGED
@@ -74,7 +74,7 @@ def decode_audio(encoded_file_path):
|
|
74 |
return f"Decoding error: {e}"
|
75 |
|
76 |
@spaces.GPU(duration=180)
|
77 |
-
def stream_decode_audio(encoded_file_path) -> Generator[
|
78 |
try:
|
79 |
# Load encoded data from the .owie file
|
80 |
with open(encoded_file_path, 'rb') as temp_file:
|
@@ -85,15 +85,18 @@ def stream_decode_audio(encoded_file_path) -> Generator[np.ndarray, None, None]:
|
|
85 |
|
86 |
# Decode the audio in chunks
|
87 |
chunk_size = 16000 # 1 second of audio at 16kHz
|
|
|
88 |
with torch.no_grad():
|
89 |
for i in range(0, z.shape[2], chunk_size):
|
90 |
z_chunk = z[:, :, i:i+chunk_size]
|
91 |
audio_chunk = agc.decode(z_chunk)
|
92 |
-
yield
|
|
|
|
|
93 |
|
94 |
except Exception as e:
|
95 |
-
yield np.zeros((2, chunk_size)) # Return silence in case of error
|
96 |
print(f"Streaming decoding error: {e}")
|
|
|
97 |
|
98 |
# Gradio Interface
|
99 |
with gr.Blocks() as demo:
|
|
|
74 |
return f"Decoding error: {e}"
|
75 |
|
76 |
@spaces.GPU(duration=180)
|
77 |
+
def stream_decode_audio(encoded_file_path) -> Generator[tuple, None, None]:
|
78 |
try:
|
79 |
# Load encoded data from the .owie file
|
80 |
with open(encoded_file_path, 'rb') as temp_file:
|
|
|
85 |
|
86 |
# Decode the audio in chunks
|
87 |
chunk_size = 16000 # 1 second of audio at 16kHz
|
88 |
+
sample_rate = 16000 # AGC model's output sample rate
|
89 |
with torch.no_grad():
|
90 |
for i in range(0, z.shape[2], chunk_size):
|
91 |
z_chunk = z[:, :, i:i+chunk_size]
|
92 |
audio_chunk = agc.decode(z_chunk)
|
93 |
+
# Convert to numpy, then to list, and yield as tuple with sample rate
|
94 |
+
audio_data = audio_chunk.squeeze(0).cpu().numpy().T.tolist()
|
95 |
+
yield (sample_rate, audio_data)
|
96 |
|
97 |
except Exception as e:
|
|
|
98 |
print(f"Streaming decoding error: {e}")
|
99 |
+
yield (sample_rate, [[0] * chunk_size, [0] * chunk_size]) # Return silence in case of error
|
100 |
|
101 |
# Gradio Interface
|
102 |
with gr.Blocks() as demo:
|