Skip to content

Commit

Permalink
clip amplitude for audio. #79
Browse files Browse the repository at this point in the history
  • Loading branch information
lanpa committed Feb 17, 2018
1 parent 0d83dd1 commit 3deaf0d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tensorboardX/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ def make_image(tensor):
def audio(tag, tensor, sample_rate=44100):
tensor = makenp(tensor)
tensor = tensor.squeeze()
if abs(tensor).max()>1:
print('warning: audio amplitude out of range, auto clipped.')
tensor = tensor.clip(-1, 1)
assert(tensor.ndim == 1), 'input tensor should be 1 dimensional.'

tensor_list = [int(32767.0 * x) for x in tensor]
Expand Down
2 changes: 1 addition & 1 deletion tensorboardX/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def add_audio(self, tag, snd_tensor, global_step=None, sample_rate=44100):
sample_rate (int): sample rate in Hz
Shape:
snd_tensor: :math:`(1, L)`. The values should between [-1, 1].
snd_tensor: :math:`(1, L)`. The values should lie between [-1, 1].
"""
self.file_writer.add_summary(audio(tag, snd_tensor, sample_rate=sample_rate), global_step)

Expand Down

0 comments on commit 3deaf0d

Please sign in to comment.