File size: 1,331 Bytes
f015573 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "0ba083d2",
"metadata": {},
"outputs": [],
"source": [
"import torch\n",
"from vocos import Vocos\n",
"import torchaudio\n",
"\n",
"vocos = Vocos.from_pretrained(\"charactr/vocos-encodec-24khz\")\n",
"\n",
"bandwidth_id = torch.tensor([3]) # 12 kbps\n",
"\n",
"y, sr = torchaudio.load(\"./samples/konichihaaaaaaaaaa.wav\")\n",
"if y.size(0) > 1: # mix to mono\n",
" y = y.mean(dim=0, keepdim=True)\n",
"y = torchaudio.functional.resample(y, orig_freq=sr, new_freq=24000)\n",
"\n",
"with torch.no_grad():\n",
" y_hat = vocos(y, bandwidth_id=bandwidth_id)\n",
"\n",
"torchaudio.save(\"samples/rap_base_vocos.wav\", y_hat, 24000)\n",
"\n",
"import IPython.display as ipd\n",
"ipd.Audio(\"samples/rap_base_vocos.wav\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|