Skip to content

Commit

Permalink
Fix path normalization for StreamWriter-based save operation
Browse files Browse the repository at this point in the history
Follow up of pytorch#3243. Save compat module had different semantics than info and load,
which requires different way of performing path normalization.
  • Loading branch information
mthrok committed Apr 6, 2023
1 parent f4d94ca commit 93a68af
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion torchaudio/_backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def save(
buffer_size: int = 4096,
) -> None:
save_audio(
os.path.normpath(uri),
uri,
src,
sample_rate,
channels_first,
Expand Down
5 changes: 3 additions & 2 deletions torchaudio/io/_stream_writer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os.path
from dataclasses import dataclass
from typing import BinaryIO, Dict, Optional, Union

Expand Down Expand Up @@ -160,12 +161,12 @@ class StreamWriter:

def __init__(
self,
dst: Union[str, BinaryIO],
dst: Union[str, BinaryIO, os.PathLike],
format: Optional[str] = None,
buffer_size: int = 4096,
):
if isinstance(dst, str):
self._s = torchaudio.lib._torchaudio_ffmpeg.StreamWriter(dst, format)
self._s = torchaudio.lib._torchaudio_ffmpeg.StreamWriter(os.path.normpath(dst), format)
elif hasattr(dst, "write"):
self._s = torchaudio.lib._torchaudio_ffmpeg.StreamWriterFileObj(dst, format, buffer_size)
else:
Expand Down

0 comments on commit 93a68af

Please sign in to comment.