saeki commited on
Commit
cbd6aaa
·
1 Parent(s): e7f4858
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -67,6 +67,8 @@ def calc_spectrogram(wav, config):
67
  return log_spec
68
 
69
  def transfer(audio):
 
 
70
  wp_src = pathlib.Path("aet_sample/src.wav")
71
  wav_src, sr = torchaudio.load(wp_src)
72
  sr_inp, wav_tar = audio
@@ -91,16 +93,16 @@ def transfer(audio):
91
  strict=False
92
  )
93
 
94
- encoder_src = src_model.encoder
95
- channelfeats_src = src_model.channelfeats
96
- channel_src = src_model.channel
97
 
98
  _, enc_hidden_src = encoder_src(
99
- melspec_src.unsqueeze(0).unsqueeze(1).transpose(2, 3)
100
  )
101
  chfeats_src = channelfeats_src(enc_hidden_src)
102
  wav_transfer = channel_src(wav_tar.unsqueeze(0), chfeats_src)
103
- wav_transfer = wav_transfer.detach().numpy()[0, :]
104
  return sr, wav_transfer
105
 
106
  if __name__ == "__main__":
 
67
  return log_spec
68
 
69
  def transfer(audio):
70
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
71
+
72
  wp_src = pathlib.Path("aet_sample/src.wav")
73
  wav_src, sr = torchaudio.load(wp_src)
74
  sr_inp, wav_tar = audio
 
93
  strict=False
94
  )
95
 
96
+ encoder_src = src_model.encoder.to(device)
97
+ channelfeats_src = src_model.channelfeats.to(device)
98
+ channel_src = src_model.channel.to(device)
99
 
100
  _, enc_hidden_src = encoder_src(
101
+ melspec_src.unsqueeze(0).unsqueeze(1).transpose(2, 3).to(device)
102
  )
103
  chfeats_src = channelfeats_src(enc_hidden_src)
104
  wav_transfer = channel_src(wav_tar.unsqueeze(0), chfeats_src)
105
+ wav_transfer = wav_transfer.cpu().detach().numpy()[0, :]
106
  return sr, wav_transfer
107
 
108
  if __name__ == "__main__":