Skip to content

Commit 9da92cd

Browse files
mthrokfacebook-github-bot
authored andcommitted
Fix path normalization for StreamWriter-based save operation (#3248)
Summary: Follow up of #3243. Save compat module had different semantics than info and load, which requires different way of performing path normalization. Pull Request resolved: #3248 Reviewed By: hwangjeff Differential Revision: D44774997 Pulled By: mthrok fbshipit-source-id: 4b967ae3ca6b45850d455b8e95aaa31762c5457e
1 parent ae614ed commit 9da92cd

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

torchaudio/_backend/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def save(
122122
buffer_size: int = 4096,
123123
) -> None:
124124
save_audio(
125-
os.path.normpath(uri),
125+
uri,
126126
src,
127127
sample_rate,
128128
channels_first,

torchaudio/io/_compat.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,11 @@ def save_audio(
204204
bits_per_sample: Optional[int] = None,
205205
buffer_size: int = 4096,
206206
) -> None:
207-
if hasattr(uri, "write") and format is None:
208-
raise RuntimeError("'format' is required when saving to file object.")
207+
if hasattr(uri, "write"):
208+
if format is None:
209+
raise RuntimeError("'format' is required when saving to file object.")
210+
else:
211+
uri = os.path.normpath(uri)
209212
s = StreamWriter(uri, format=format, buffer_size=buffer_size)
210213
if format is None:
211214
tokens = str(uri).split(".")

0 commit comments

Comments
 (0)