camenduru commited on
Commit
defdd8b
1 Parent(s): 3238f77

Update worker_runpod.py

Browse files
Files changed (1) hide show
  1. worker_runpod.py +4 -1
worker_runpod.py CHANGED
@@ -48,6 +48,9 @@ def generate(input):
48
  )
49
  output = rearrange(output, "b d n -> d (b n)")
50
  output = output.to(torch.float32).div(torch.max(torch.abs(output))).clamp(-1, 1).mul(32767).to(torch.int16).cpu()
 
 
 
51
  torchaudio.save("/content/output.wav", output, sample_rate)
52
 
53
  result = "/content/output.wav"
@@ -86,4 +89,4 @@ def generate(input):
86
  else:
87
  return {"result": "ERROR"}
88
 
89
- runpod.serverless.start({"handler": generate})
 
48
  )
49
  output = rearrange(output, "b d n -> d (b n)")
50
  output = output.to(torch.float32).div(torch.max(torch.abs(output))).clamp(-1, 1).mul(32767).to(torch.int16).cpu()
51
+ max_length = sample_rate * seconds_total
52
+ if output.shape[1] > max_length:
53
+ output = output[:, :max_length]
54
  torchaudio.save("/content/output.wav", output, sample_rate)
55
 
56
  result = "/content/output.wav"
 
89
  else:
90
  return {"result": "ERROR"}
91
 
92
+ runpod.serverless.start({"handler": generate})