daft.functions.resample#
resample #
resample(file_expr: Expression, sample_rate: int) -> Expression
Resample a audio file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_expr | AudioFile Expression | The audio file to resample. | required |
sample_rate | int | The sample rate to resample to. | required |
Returns:
| Name | Type | Description |
|---|---|---|
Expression | Tensor[Python] Expression | The resampled audio file. |
Example
import daft from daft.functions import audio_file, resample
Discover the audio files (returns a dataframe with ['path', 'size'] columns)#
df = daft.from_glob_path("hf://datasets/Eventual-Inc/sample-files/audio/*.mp3")
df = ( ... df.with_column("file", audio_file(daft.col("path"))) ... .with_column("resampled", resample(daft.col("file"), sample_rate=16000)) ... .select("path", "size", "resampled") ... ) df.show(3) ╭────────────────────────────────┬─────────┬──────────────────────────╮ │ path ┆ size ┆ resampled │ │ --- ┆ --- ┆ --- │ │ String ┆ Int64 ┆ Tensor[Float64] │ ╞════════════════════════════════╪═════════╪══════════════════════════╡ │ hf://datasets/Eventual-Inc/sa… ┆ 822924 ┆
│ ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ │ hf://datasets/Eventual-Inc/sa… ┆ 618408 ┆ │ ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ │ hf://datasets/Eventual-Inc/sa… ┆ 1190736 ┆ │ ╰────────────────────────────────┴─────────┴──────────────────────────╯ (Showing first 3 rows)
Source code in daft/functions/audio.py
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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |