Skip to content

Commit

Permalink
[update] add sampling rate
Browse files Browse the repository at this point in the history
  • Loading branch information
Jourdelune committed Jun 2, 2024
1 parent bac2ec8 commit 82020d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions dataset/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(
self,
lyric_path: str,
audio_path: str,
sample_rate: int = None,
export_path: str = None,
clean: bool = False,
):
Expand All @@ -22,13 +23,15 @@ def __init__(
Args:
lyric_path (str): the path to the lyrics folder
audio_path (str): the path to the audio folder
sample_rate (int, optional): the sample rate of the audio. Defaults to None.
export_path (str, optional): the path to export data. Defaults to None.
clean (bool, optional): remove all data in the export path. Defaults to False.
"""

self.lyric_path = lyric_path
self.audio_path = audio_path
self.export_path = export_path
self.sample_rate = sample_rate

if clean:
self.remove_export_folder()
Expand Down Expand Up @@ -123,6 +126,9 @@ def _export_audio(self, audios: List[AudioSegment], file_name: str) -> None:
if self.export_path:
path = f"{self.export_path}/audio/{file_name}_{i}.wav"

if self.sample_rate:
audio = audio.set_frame_rate(self.sample_rate)

audio.export(path, format="wav")

def _export_lyric(self, lyrics: List[str], file_name: str) -> None:
Expand Down
2 changes: 2 additions & 0 deletions process.py → process_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
parser.add_argument("--audio_path", type=str, default="dataset/audio")
parser.add_argument("--lyric_path", type=str, default="dataset/lyrics")
parser.add_argument("--export_path", type=str, default="dataset/export")
parser.add_argument("--sample_rate", type=int, default=None)
parser.add_argument("--clean", type=bool, default=False)

args = parser.parse_args()
process = DatasetProcess(
lyric_path=args.lyric_path,
audio_path=args.audio_path,
sample_rate=args.sample_rate,
export_path=args.export_path,
clean=args.clean,
)
Expand Down

0 comments on commit 82020d4

Please sign in to comment.