(semantic_token_file, config_path, ckpt_path, outdir, sample_rate=24000)
| 73 | |
| 74 | |
| 75 | def reconstruct(semantic_token_file, config_path, ckpt_path, outdir, sample_rate=24000): |
| 76 | if not os.path.isdir(outdir): |
| 77 | os.makedirs(outdir, exist_ok=True) |
| 78 | device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') |
| 79 | bandwidth_id = torch.tensor([0]).to(device) |
| 80 | wavtokenizer = WavTokenizer.from_pretrained_feat(config_path, ckpt_path).to(device) |
| 81 | utt2semantic_token = torch.load(semantic_token_file) |
| 82 | for utt in tqdm(utt2semantic_token.keys()): |
| 83 | token = utt2semantic_token[utt] |
| 84 | new_tensor = torch.tensor(token).to(device).unsqueeze(0) |
| 85 | features = wavtokenizer.codes_to_features(new_tensor) |
| 86 | wav = wavtokenizer.decode(features, bandwidth_id=bandwidth_id) |
| 87 | wav = wav.cpu().detach() |
| 88 | torchaudio.save(outdir + "/" + utt + ".wav", wav, sample_rate=sample_rate, encoding='PCM_S', bits_per_sample=16) |
| 89 | |
| 90 | if __name__ == "__main__": |
| 91 | parser = argparse.ArgumentParser() |
nothing calls this directly
no test coverage detected