Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dataset/librispeech/librispeech.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

from paddlespeech.dataset.download import download
from paddlespeech.dataset.download import unpack
from paddlespeech.utils.argparse import strtobool

URL_ROOT = "http://openslr.elda.org/resources/12"
#URL_ROOT = "https://openslr.magicdatatech.com/resources/12"
Expand Down Expand Up @@ -63,7 +64,7 @@
parser.add_argument(
"--full_download",
default="True",
type=distutils.util.strtobool,
type=strtobool,
help="Download all datasets for Librispeech."
" If False, only download a minimal requirement (test-clean, dev-clean"
" train-clean-100). (default: %(default)s)")
Expand Down
3 changes: 2 additions & 1 deletion examples/ami/sd0/local/ami_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
from ami_splits import get_AMI_split
from dataio import load_pkl
from dataio import save_pkl
from distutils.util import strtobool

from paddlespeech.utils.argparse import strtobool

logger = logging.getLogger(__name__)
SAMPLERATE = 16000
Expand Down
3 changes: 2 additions & 1 deletion paddlespeech/s2t/decoders/recog_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

import configargparse
import numpy as np
from distutils.util import strtobool

from paddlespeech.utils.argparse import strtobool


def get_parser():
Expand Down
6 changes: 2 additions & 4 deletions paddlespeech/s2t/exps/whisper/test_wav.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from paddlespeech.s2t.models.whisper import Whisper
from paddlespeech.s2t.training.cli import default_argument_parser
from paddlespeech.s2t.utils.log import Log
from paddlespeech.utils.argparse import strtobool

logger = Log(__name__).getlog()

Expand Down Expand Up @@ -103,10 +104,7 @@ def main(config, args):
parser.add_argument(
"--audio_file", type=str, help="path of the input audio file")
parser.add_argument(
"--debug",
type=distutils.util.strtobool,
default=False,
help="for debug.")
"--debug", type=strtobool, default=False, help="for debug.")
args = parser.parse_args()

config = CfgNode(new_allowed=True)
Expand Down
4 changes: 3 additions & 1 deletion paddlespeech/s2t/training/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import distutils
from yacs.config import CfgNode

from paddlespeech.utils.argparse import strtobool


class ExtendAction(argparse.Action):
"""
Expand Down Expand Up @@ -73,7 +75,7 @@ def default_argument_parser(parser=None):
'--conf', type=open, action=LoadFromFile, help="config file.")
parser.add_argument(
"--debug",
type=distutils.util.strtobool,
type=strtobool,
default=False,
help="logging with debug mode.")
parser.add_argument(
Expand Down
5 changes: 3 additions & 2 deletions paddlespeech/s2t/utils/cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
from collections.abc import Sequence

import numpy
from distutils.util import strtobool as dist_strtobool

from paddlespeech.utils.argparse import strtobool as dist_strtobool


def strtobool(x):
# distutils.util.strtobool returns integer, but it's confusing,
# paddlespeech.utils.argparse.strtobool returns integer, but it's confusing,
return bool(dist_strtobool(x))


Expand Down
27 changes: 25 additions & 2 deletions paddlespeech/utils/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

import distutils

__all__ = ["print_arguments", "add_arguments", "get_commandline_args"]
__all__ = [
"print_arguments", "add_arguments", "get_commandline_args", "strtobool"
]


def get_commandline_args():
Expand Down Expand Up @@ -80,6 +82,27 @@ def print_arguments(args, info=None):
print("-----------------------------------------------------------")


def strtobool(value):
"""Convert a string value to an integer boolean (1 for True, 0 for False).

The function recognizes the following strings as True (case insensitive):
- "yes"
- "true"
- "1"

All other values are considered False.

NOTE: After Python 3.10, the distutils module, particularly distutils.util, has been partially deprecated. To maintain compatibility with existing code, the strtobool function implemented here.
"""
if isinstance(value, bool):
return int(value)
value = value.strip().lower()
if value in ('yes', 'true', '1'):
return 1
else:
return 0


def add_arguments(argname, type, default, help, argparser, **kwargs):
"""Add argparse's argument.

Expand All @@ -91,7 +114,7 @@ def add_arguments(argname, type, default, help, argparser, **kwargs):
add_argument("name", str, "Jonh", "User name.", parser)
args = parser.parse_args()
"""
type = distutils.util.strtobool if type == bool else type
type = strtobool if type == bool else type
argparser.add_argument(
"--" + argname,
default=default,
Expand Down
3 changes: 2 additions & 1 deletion paddlespeech/vector/cluster/diarization.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import numpy as np
import scipy
import sklearn
from distutils.util import strtobool
from scipy import linalg
from scipy import sparse
from scipy.sparse.csgraph import connected_components
Expand All @@ -34,6 +33,8 @@
from sklearn.cluster._kmeans import k_means
from sklearn.neighbors import kneighbors_graph

from paddlespeech.utils.argparse import strtobool


def _graph_connected_component(graph, node_id):
"""
Expand Down
3 changes: 2 additions & 1 deletion utils/DER.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
import subprocess

import numpy as np
from distutils.util import strtobool

from paddlespeech.utils.argparse import strtobool

FILE_IDS = re.compile(r"(?<=Speaker Diarization for).+(?=\*\*\*)")
SCORED_SPEAKER_TIME = re.compile(r"(?<=SCORED SPEAKER TIME =)[\d.]+")
Expand Down
3 changes: 2 additions & 1 deletion utils/addjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import logging
import sys

from distutils.util import strtobool
from espnet.utils.cli_utils import get_commandline_args

from paddlespeech.utils.argparse import strtobool

is_python2 = sys.version_info[0] == 2


Expand Down
2 changes: 1 addition & 1 deletion utils/apply-cmvn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

import kaldiio
import numpy
from distutils.util import strtobool

from paddlespeech.audio.transform.cmvn import CMVN
from paddlespeech.s2t.utils.cli_readers import file_reader_helper
from paddlespeech.s2t.utils.cli_utils import get_commandline_args
from paddlespeech.s2t.utils.cli_utils import is_scipy_wav_style
from paddlespeech.s2t.utils.cli_writers import file_writer_helper
from paddlespeech.utils.argparse import strtobool


def get_parser():
Expand Down
3 changes: 1 addition & 2 deletions utils/copy-feats.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
import argparse
import logging

from distutils.util import strtobool

from paddlespeech.audio.transform.transformation import Transformation
from paddlespeech.s2t.utils.cli_readers import file_reader_helper
from paddlespeech.s2t.utils.cli_utils import get_commandline_args
from paddlespeech.s2t.utils.cli_utils import is_scipy_wav_style
from paddlespeech.s2t.utils.cli_writers import file_writer_helper
from paddlespeech.utils.argparse import strtobool


def get_parser():
Expand Down
3 changes: 1 addition & 2 deletions utils/merge_scp2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import sys
from io import open

from distutils.util import strtobool

from paddlespeech.s2t.utils.cli_utils import get_commandline_args
from paddlespeech.utils.argparse import strtobool

PY2 = sys.version_info[0] == 2
sys.stdin = codecs.getreader("utf-8")(sys.stdin if PY2 else sys.stdin.buffer)
Expand Down