owiedotch commited on
Commit
055ea67
·
verified ·
1 Parent(s): f28e066

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
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
- # Create in-memory file for audio
108
- output_buffer = io.BytesIO()
109
- sf.write(output_buffer, waveform[0, 0], 32000, format='WAV')
110
- output_buffer.seek(0)
111
 
112
- # Verify the buffer has content
113
- if output_buffer.getbuffer().nbytes == 0:
114
- return None, "Error: Failed to generate audio"
115
 
116
- return output_buffer, f"Decoded {tokens.shape[1]} tokens to audio"
 
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
- # Create in-memory file
159
- output_buffer = io.BytesIO()
160
- sf.write(output_buffer, waveform[0, 0], 32000, format='WAV')
161
- output_buffer.seek(0)
162
 
163
- # Verify the buffer has content
164
- if output_buffer.getbuffer().nbytes == 0:
165
- return None, "Error: Failed to generate audio"
166
 
167
- return output_buffer, f"Encoded to {tokens.shape[1]} tokens\nDecoded {tokens.shape[1]} tokens to audio"
 
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)}"