"src/vscode:/vscode.git/clone" did not exist on "eb90d3be139cbb353e443460ee13f8fabe098cfb"
Commit 6e8045ea authored by Soumith Chintala's avatar Soumith Chintala
Browse files

add docstrings for save and load

parent 74b5faa7
...@@ -23,6 +23,26 @@ def check_input(src): ...@@ -23,6 +23,26 @@ def check_input(src):
raise TypeError('Expected a CPU based tensor, got %s' % type(src)) raise TypeError('Expected a CPU based tensor, got %s' % type(src))
def load(filepath, out=None, normalization=None): def load(filepath, out=None, normalization=None):
"""Loads an audio file from disk into a Tensor
Args:
filepath (string): path to audio file
out (Tensor, optional): an output Tensor to use instead of creating one
normalization (bool or number, optional): If boolean `True`, then output is divided by `1 << 31` (assumes 16-bit depth audio, and normalizes to `[0, 1]`. If `number`, then output is divided by that number
Returns: tuple(Tensor, int)
- Tensor: output Tensor of size `[L x C]` where L is the number of audio frames, C is the number of channels
- int: the sample-rate of the audio (as listed in the metadata of the file)
Example::
>>> data, sample_rate = torchaudio.load('foo.mp3')
>>> print(data.size())
torch.Size([278756, 2])
>>> print(sample_rate)
44100
"""
# check if valid file # check if valid file
if not os.path.isfile(filepath): if not os.path.isfile(filepath):
raise OSError("{} not found or is a directory".format(filepath)) raise OSError("{} not found or is a directory".format(filepath))
...@@ -45,6 +65,19 @@ def load(filepath, out=None, normalization=None): ...@@ -45,6 +65,19 @@ def load(filepath, out=None, normalization=None):
return out, sample_rate return out, sample_rate
def save(filepath, src, sample_rate): def save(filepath, src, sample_rate):
"""Saves a Tensor with audio signal to disk as a standard format like mp3, wav, etc.
Args:
filepath (string): path to audio file
src (Tensor): an input 2D Tensor of shape `[L x C]` where L is the number of audio frames, C is the number of channels
sample_rate (int): the sample-rate of the audio to be saved
Example::
>>> data, sample_rate = torchaudio.load('foo.mp3')
>>> torchaudio.save('foo.wav', data, sample_rate)
"""
# check if save directory exists # check if save directory exists
abs_dirpath = os.path.dirname(os.path.abspath(filepath)) abs_dirpath = os.path.dirname(os.path.abspath(filepath))
if not os.path.isdir(abs_dirpath): if not os.path.isdir(abs_dirpath):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment