test.py 732 Bytes
Newer Older
Soumith Chintala's avatar
Soumith Chintala committed
1
2
3
4

import torch
import torch.nn as nn
import torchaudio
David Pollack's avatar
David Pollack committed
5
import math
Soumith Chintala's avatar
Soumith Chintala committed
6

David Pollack's avatar
David Pollack committed
7
8
9
steam_train = "assets/steam-train-whistle-daniel_simon.mp3"

x, sample_rate = torchaudio.load(steam_train)
Soumith Chintala's avatar
Soumith Chintala committed
10
11
12
13
14
15
print(sample_rate)
print(x.size())
print(x[10000])
print(x.min(), x.max())
print(x.mean(), x.std())

David Pollack's avatar
David Pollack committed
16
x, sample_rate = torchaudio.load(steam_train,
Soumith Chintala's avatar
Soumith Chintala committed
17
18
19
20
21
                                 out=torch.LongTensor())
print(sample_rate)
print(x.size())
print(x[10000])
print(x.min(), x.max())
David Pollack's avatar
David Pollack committed
22
23
24
25
26
27
28
29
30
31
32
33

sine_wave = "assets/sinewave.wav"
sr = 16000
freq = 440
volume = 0.3

y = (torch.cos(2*math.pi*torch.arange(0, 4*sr) * freq/sr)).float()
y.unsqueeze_(1)
# y is between -1 and 1, so must scale
y = (y*volume*2**31).long()
torchaudio.save(sine_wave, y, sr)
print(y.min(), y.max())