Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
Torchaudio
Commits
c844ac63
Commit
c844ac63
authored
Mar 06, 2018
by
Peter Goldsborough
Committed by
Sam Gross
Mar 06, 2018
Browse files
Fixes after tensor/variable merge (#33)
parent
4a3e5006
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
3 deletions
+7
-3
torchaudio/__init__.py
torchaudio/__init__.py
+7
-3
No files found.
torchaudio/__init__.py
View file @
c844ac63
...
@@ -18,10 +18,14 @@ else:
...
@@ -18,10 +18,14 @@ else:
return
s
.
encode
(
e
)
return
s
.
encode
(
e
)
def
get_tensor_type_name
(
tensor
):
return
tensor
.
type
().
replace
(
'torch.'
,
''
).
replace
(
'Tensor'
,
''
)
def
check_input
(
src
):
def
check_input
(
src
):
if
not
torch
.
is_tensor
(
src
):
if
not
torch
.
is_tensor
(
src
):
raise
TypeError
(
'Expected a tensor, got %s'
%
type
(
src
))
raise
TypeError
(
'Expected a tensor, got %s'
%
type
(
src
))
if
not
src
.
__module__
==
'torch'
:
if
src
.
is_cuda
:
raise
TypeError
(
'Expected a CPU based tensor, got %s'
%
type
(
src
))
raise
TypeError
(
'Expected a CPU based tensor, got %s'
%
type
(
src
))
...
@@ -57,7 +61,7 @@ def load(filepath, out=None, normalization=None):
...
@@ -57,7 +61,7 @@ def load(filepath, out=None, normalization=None):
else
:
else
:
out
=
torch
.
FloatTensor
()
out
=
torch
.
FloatTensor
()
# load audio signal
# load audio signal
typename
=
type
(
out
).
__name__
.
replace
(
'Tensor'
,
''
)
typename
=
get_tensor_type_name
(
out
)
func
=
getattr
(
th_sox
,
'libthsox_{}_read_audio_file'
.
format
(
typename
))
func
=
getattr
(
th_sox
,
'libthsox_{}_read_audio_file'
.
format
(
typename
))
sample_rate_p
=
ffi
.
new
(
'int*'
)
sample_rate_p
=
ffi
.
new
(
'int*'
)
func
(
str
(
filepath
).
encode
(
"utf-8"
),
out
,
sample_rate_p
)
func
(
str
(
filepath
).
encode
(
"utf-8"
),
out
,
sample_rate_p
)
...
@@ -109,7 +113,7 @@ def save(filepath, src, sample_rate):
...
@@ -109,7 +113,7 @@ def save(filepath, src, sample_rate):
# save data to file
# save data to file
filename
,
extension
=
os
.
path
.
splitext
(
filepath
)
filename
,
extension
=
os
.
path
.
splitext
(
filepath
)
check_input
(
src
)
check_input
(
src
)
typename
=
type
(
src
).
__name__
.
replace
(
'Tensor'
,
''
)
typename
=
get_tensor_type_name
(
src
)
func
=
getattr
(
th_sox
,
'libthsox_{}_write_audio_file'
.
format
(
typename
))
func
=
getattr
(
th_sox
,
'libthsox_{}_write_audio_file'
.
format
(
typename
))
func
(
_bytes
(
filepath
,
"utf-8"
),
src
,
func
(
_bytes
(
filepath
,
"utf-8"
),
src
,
_bytes
(
extension
[
1
:],
"utf-8"
),
sample_rate
)
_bytes
(
extension
[
1
:],
"utf-8"
),
sample_rate
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment