Commit 20f34c6c authored by Raffaele Sena's avatar Raffaele Sena
Browse files

Quick and dirty fix for "bytes" not available in python2

parent 9edce71c
import os
import sys
import torch
......@@ -10,6 +11,11 @@ from ._ext import th_sox
from torchaudio import transforms
from torchaudio import datasets
if sys.version_info >= (3, 0):
_bytes = bytes
else:
_bytes = lambda s, e: s.encode(e)
def check_input(src):
if not torch.is_tensor(src):
raise TypeError('Expected a tensor, got %s' % type(src))
......@@ -64,4 +70,4 @@ def save(filepath, src, sample_rate):
check_input(src)
typename = type(src).__name__.replace('Tensor', '')
func = getattr(th_sox, 'libthsox_{}_write_audio_file'.format(typename))
func(bytes(filepath, "utf-8"), src, bytes(extension[1:], "utf-8"), sample_rate)
func(_bytes(filepath, "utf-8"), src, _bytes(extension[1:], "utf-8"), sample_rate)
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