File size: 3,134 Bytes
9c0c5c8
 
 
 
63ee254
9c0c5c8
 
 
 
 
 
 
 
 
 
63ee254
9c0c5c8
 
 
 
 
 
 
 
 
 
 
63ee254
9c0c5c8
 
 
 
c17b696
 
9c0c5c8
 
 
 
63ee254
9c0c5c8
 
 
 
c1e3d89
 
 
 
 
 
 
9c0c5c8
 
f4441f8
 
 
 
 
825c8bf
f4441f8
 
9c0c5c8
 
63ee254
9c0c5c8
 
63ee254
9c0c5c8
 
 
 
 
 
63ee254
9c0c5c8
 
63ee254
9c0c5c8
 
 
 
 
 
 
63ee254
9c0c5c8
 
63ee254
9c0c5c8
 
 
 
f4441f8
 
 
 
 
825c8bf
f4441f8
 
9c0c5c8
 
63ee254
9c0c5c8
 
63ee254
9c0c5c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63ee254
9c0c5c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2a61d194",
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "21f27189",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "sys.path.insert(0, os.path.dirname(os.path.abspath(\"\")))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "218fcdf1",
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import Audio\n",
    "from audiodiffusion.mel import Mel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5e4f8ee5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# These are the default parameters. If you change any of them, you may have to adjust the others.\n",
    "mel = Mel(x_res=256,\n",
    "          y_res=256,\n",
    "          hop_length=512,\n",
    "          sample_rate=22050,\n",
    "          n_fft=2048,\n",
    "          n_iter=32)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b2178c3f",
   "metadata": {},
   "source": [
    "### Transform slice of audio to mel spectrogram"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "61dbcd2e",
   "metadata": {},
   "outputs": [],
   "source": [
    "mel.load_audio('/home/teticio/Music/Music/A Tribe Called Quest/The Anthology/08 Can I Kick It_.mp3')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ccadcc0f",
   "metadata": {},
   "outputs": [],
   "source": [
    "image = mel.audio_slice_to_image(15)\n",
    "image"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8cec79c6",
   "metadata": {},
   "outputs": [],
   "source": [
    "image.width, image.height"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fe112fef",
   "metadata": {},
   "source": [
    "### Transform mel spectrogram back to audio"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0b268a54",
   "metadata": {},
   "outputs": [],
   "source": [
    "audio = mel.image_to_audio(image)\n",
    "Audio(data=audio, rate=mel.get_sample_rate())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a0dffbc4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "huggingface",
   "language": "python",
   "name": "huggingface"
  },
  "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.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}