prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Error with using compute-fbank-feats.py
  Hello! I tried to use script compute-fbank-feats.py to compute fbank features from wav, and tried to use it according to its documentation https://espnet.github.io/espnet/apis/utils_py.html#compute-fbank-feats-py
  
  as folllows:
  ```
  python3.7 utils/compute-fbank-feats.py scp:wav.scp ark:out.ark
  ```
  
  but got an error:
  
  ```
    File "utils/compute-fbank-feats.py", line 134, in <module>
      main()
    File "utils/compute-fbank-feats.py", line 128, in main
      fmax=args.fmax,
    File "/home/karina/.local/lib/python3.7/site-packages/espnet/transform/spectrogram.py", line 116, in logmelspectrogram
      x_stft, fs=fs, n_mels=n_mels, n_fft=n_fft, fmin=fmin, fmax=fmax, eps=eps
    File "/home/karina/.local/lib/python3.7/site-packages/espnet/transform/spectrogram.py", line 74, in stft2logmelspectrogram
      fmax = fs / 2 if fmax is None else fmax
  TypeError: unsupported operand type(s) for /: 'NoneType' and 'int'
  ```
  
  wav.scp contains this text:
  ```
  0 test.wav
  ```
  
  Does anyone have ideas how to solve this error?
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `utils/compute-fbank-feats.py`
  Content:
  ```
  1 #!/usr/bin/env python3
  2 
  3 # Copyright 2018 Nagoya University (Tomoki Hayashi)
  4 #  Apache 2.0  (http://www.apache.org/licenses/LICENSE-2.0)
  5 
  6 import argparse
  7 from distutils.util import strtobool
  8 import logging
  9 
  10 import kaldiio
  11 import numpy
  12 import resampy
  13 
  14 from espnet.transform.spectrogram import logmelspectrogram
  15 from espnet.utils.cli_utils import get_commandline_args
  16 from espnet.utils.cli_writers import file_writer_helper
  17 from espnet2.utils.types import int_or_none
  18 
  19 
  20 def get_parser():
  21     parser = argparse.ArgumentParser(
  22         description="compute FBANK feature from WAV",
  23         formatter_class=argparse.ArgumentDefaultsHelpFormatter,
  24     )
  25     parser.add_argument("--fs", type=int_or_none, help="Sampling frequency")
  26     parser.add_argument(
  27         "--fmax", type=int_or_none, default=None, nargs="?", help="Maximum frequency"
  28     )
  29     parser.add_argument(
  30         "--fmin", type=int_or_none, default=None, nargs="?", help="Minimum frequency"
  31     )
  32     parser.add_argument("--n_mels", type=int, default=80, help="Number of mel basis")
  33     parser.add_argument("--n_fft", type=int, default=1024, help="FFT length in point")
  34     parser.add_argument(
  35         "--n_shift", type=int, default=512, help="Shift length in point"
  36     )
  37     parser.add_argument(
  38         "--win_length",
  39         type=int_or_none,
  40         default=None,
  41         nargs="?",
  42         help="Analisys window length in point",
  43     )
  44     parser.add_argument(
  45         "--window",
  46         type=str,
  47         default="hann",
  48         choices=["hann", "hamming"],
  49         help="Type of window",
  50     )
  51     parser.add_argument(
  52         "--write-num-frames", type=str, help="Specify wspecifer for utt2num_frames"
  53     )
  54     parser.add_argument(
  55         "--filetype",
  56         type=str,
  57         default="mat",
  58         choices=["mat", "hdf5"],
  59         help="Specify the file format for output. "
  60         '"mat" is the matrix format in kaldi',
  61     )
  62     parser.add_argument(
  63         "--compress", type=strtobool, default=False, help="Save in compressed format"
  64     )
  65     parser.add_argument(
  66         "--compression-method",
  67         type=int,
  68         default=2,
  69         help="Specify the method(if mat) or " "gzip-level(if hdf5)",
  70     )
  71     parser.add_argument("--verbose", "-V", default=0, type=int, help="Verbose option")
  72     parser.add_argument(
  73         "--normalize",
  74         choices=[1, 16, 24, 32],
  75         type=int,
  76         default=None,
  77         help="Give the bit depth of the PCM, "
  78         "then normalizes data to scale in [-1,1]",
  79     )
  80     parser.add_argument("rspecifier", type=str, help="WAV scp file")
  81     parser.add_argument(
  82         "--segments",
  83         type=str,
  84         help="segments-file format: each line is either"
  85         "<segment-id> <recording-id> <start-time> <end-time>"
  86         "e.g. call-861225-A-0050-0065 call-861225-A 5.0 6.5",
  87     )
  88     parser.add_argument("wspecifier", type=str, help="Write specifier")
  89     return parser
  90 
  91 
  92 def main():
  93     parser = get_parser()
  94     args = parser.parse_args()
  95 
  96     logfmt = "%(asctime)s (%(module)s:%(lineno)d) %(levelname)s: %(message)s"
  97     if args.verbose > 0:
  98         logging.basicConfig(level=logging.INFO, format=logfmt)
  99     else:
  100         logging.basicConfig(level=logging.WARN, format=logfmt)
  101     logging.info(get_commandline_args())
  102 
  103     with kaldiio.ReadHelper(
  104         args.rspecifier, segments=args.segments
  105     ) as reader, file_writer_helper(
  106         args.wspecifier,
  107         filetype=args.filetype,
  108         write_num_frames=args.write_num_frames,
  109         compress=args.compress,
  110         compression_method=args.compression_method,
  111     ) as writer:
  112         for utt_id, (rate, array) in reader:
  113             array = array.astype(numpy.float32)
  114             if args.fs is not None and rate != args.fs:
  115                 array = resampy.resample(array, rate, args.fs, axis=0)
  116             if args.normalize is not None and args.normalize != 1:
  117                 array = array / (1 << (args.normalize - 1))
  118 
  119             lmspc = logmelspectrogram(
  120                 x=array,
  121                 fs=args.fs,
  122                 n_mels=args.n_mels,
  123                 n_fft=args.n_fft,
  124                 n_shift=args.n_shift,
  125                 win_length=args.win_length,
  126                 window=args.window,
  127                 fmin=args.fmin,
  128                 fmax=args.fmax,
  129             )
  130             writer[utt_id] = lmspc
  131 
  132 
  133 if __name__ == "__main__":
  134     main()
  135
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/utils/compute-fbank-feats.py b/utils/compute-fbank-feats.py
  --- a/utils/compute-fbank-feats.py
  +++ b/utils/compute-fbank-feats.py
  @@ -118,7 +118,7 @@
   
               lmspc = logmelspectrogram(
                   x=array,
  -                fs=args.fs,
  +                fs=args.fs if args.fs is not None else rate,
                   n_mels=args.n_mels,
                   n_fft=args.n_fft,
                   n_shift=args.n_shift,
  
verification_info: {"golden_diff": "diff --git a/utils/compute-fbank-feats.py b/utils/compute-fbank-feats.py\n--- a/utils/compute-fbank-feats.py\n+++ b/utils/compute-fbank-feats.py\n@@ -118,7 +118,7 @@\n \n             lmspc = logmelspectrogram(\n                 x=array,\n-                fs=args.fs,\n+                fs=args.fs if args.fs is not None else rate,\n                 n_mels=args.n_mels,\n                 n_fft=args.n_fft,\n                 n_shift=args.n_shift,\n", "issue": "Error with using compute-fbank-feats.py\nHello! I tried to use script compute-fbank-feats.py to compute fbank features from wav, and tried to use it according to its documentation https://espnet.github.io/espnet/apis/utils_py.html#compute-fbank-feats-py\r\n\r\nas folllows:\r\n```\r\npython3.7 utils/compute-fbank-feats.py scp:wav.scp ark:out.ark\r\n```\r\n\r\nbut got an error:\r\n\r\n```\r\n  File \"utils/compute-fbank-feats.py\", line 134, in <module>\r\n    main()\r\n  File \"utils/compute-fbank-feats.py\", line 128, in main\r\n    fmax=args.fmax,\r\n  File \"/home/karina/.local/lib/python3.7/site-packages/espnet/transform/spectrogram.py\", line 116, in logmelspectrogram\r\n    x_stft, fs=fs, n_mels=n_mels, n_fft=n_fft, fmin=fmin, fmax=fmax, eps=eps\r\n  File \"/home/karina/.local/lib/python3.7/site-packages/espnet/transform/spectrogram.py\", line 74, in stft2logmelspectrogram\r\n    fmax = fs / 2 if fmax is None else fmax\r\nTypeError: unsupported operand type(s) for /: 'NoneType' and 'int'\r\n```\r\n\r\nwav.scp contains this text:\r\n```\r\n0 test.wav\r\n```\r\n\r\nDoes anyone have ideas how to solve this error?\n", "before_files": [{"content": "#!/usr/bin/env python3\n\n# Copyright 2018 Nagoya University (Tomoki Hayashi)\n#  Apache 2.0  (http://www.apache.org/licenses/LICENSE-2.0)\n\nimport argparse\nfrom distutils.util import strtobool\nimport logging\n\nimport kaldiio\nimport numpy\nimport resampy\n\nfrom espnet.transform.spectrogram import logmelspectrogram\nfrom espnet.utils.cli_utils import get_commandline_args\nfrom espnet.utils.cli_writers import file_writer_helper\nfrom espnet2.utils.types import int_or_none\n\n\ndef get_parser():\n    parser = argparse.ArgumentParser(\n        description=\"compute FBANK feature from WAV\",\n        formatter_class=argparse.ArgumentDefaultsHelpFormatter,\n    )\n    parser.add_argument(\"--fs\", type=int_or_none, help=\"Sampling frequency\")\n    parser.add_argument(\n        \"--fmax\", type=int_or_none, default=None, nargs=\"?\", help=\"Maximum frequency\"\n    )\n    parser.add_argument(\n        \"--fmin\", type=int_or_none, default=None, nargs=\"?\", help=\"Minimum frequency\"\n    )\n    parser.add_argument(\"--n_mels\", type=int, default=80, help=\"Number of mel basis\")\n    parser.add_argument(\"--n_fft\", type=int, default=1024, help=\"FFT length in point\")\n    parser.add_argument(\n        \"--n_shift\", type=int, default=512, help=\"Shift length in point\"\n    )\n    parser.add_argument(\n        \"--win_length\",\n        type=int_or_none,\n        default=None,\n        nargs=\"?\",\n        help=\"Analisys window length in point\",\n    )\n    parser.add_argument(\n        \"--window\",\n        type=str,\n        default=\"hann\",\n        choices=[\"hann\", \"hamming\"],\n        help=\"Type of window\",\n    )\n    parser.add_argument(\n        \"--write-num-frames\", type=str, help=\"Specify wspecifer for utt2num_frames\"\n    )\n    parser.add_argument(\n        \"--filetype\",\n        type=str,\n        default=\"mat\",\n        choices=[\"mat\", \"hdf5\"],\n        help=\"Specify the file format for output. \"\n        '\"mat\" is the matrix format in kaldi',\n    )\n    parser.add_argument(\n        \"--compress\", type=strtobool, default=False, help=\"Save in compressed format\"\n    )\n    parser.add_argument(\n        \"--compression-method\",\n        type=int,\n        default=2,\n        help=\"Specify the method(if mat) or \" \"gzip-level(if hdf5)\",\n    )\n    parser.add_argument(\"--verbose\", \"-V\", default=0, type=int, help=\"Verbose option\")\n    parser.add_argument(\n        \"--normalize\",\n        choices=[1, 16, 24, 32],\n        type=int,\n        default=None,\n        help=\"Give the bit depth of the PCM, \"\n        \"then normalizes data to scale in [-1,1]\",\n    )\n    parser.add_argument(\"rspecifier\", type=str, help=\"WAV scp file\")\n    parser.add_argument(\n        \"--segments\",\n        type=str,\n        help=\"segments-file format: each line is either\"\n        \"<segment-id> <recording-id> <start-time> <end-time>\"\n        \"e.g. call-861225-A-0050-0065 call-861225-A 5.0 6.5\",\n    )\n    parser.add_argument(\"wspecifier\", type=str, help=\"Write specifier\")\n    return parser\n\n\ndef main():\n    parser = get_parser()\n    args = parser.parse_args()\n\n    logfmt = \"%(asctime)s (%(module)s:%(lineno)d) %(levelname)s: %(message)s\"\n    if args.verbose > 0:\n        logging.basicConfig(level=logging.INFO, format=logfmt)\n    else:\n        logging.basicConfig(level=logging.WARN, format=logfmt)\n    logging.info(get_commandline_args())\n\n    with kaldiio.ReadHelper(\n        args.rspecifier, segments=args.segments\n    ) as reader, file_writer_helper(\n        args.wspecifier,\n        filetype=args.filetype,\n        write_num_frames=args.write_num_frames,\n        compress=args.compress,\n        compression_method=args.compression_method,\n    ) as writer:\n        for utt_id, (rate, array) in reader:\n            array = array.astype(numpy.float32)\n            if args.fs is not None and rate != args.fs:\n                array = resampy.resample(array, rate, args.fs, axis=0)\n            if args.normalize is not None and args.normalize != 1:\n                array = array / (1 << (args.normalize - 1))\n\n            lmspc = logmelspectrogram(\n                x=array,\n                fs=args.fs,\n                n_mels=args.n_mels,\n                n_fft=args.n_fft,\n                n_shift=args.n_shift,\n                win_length=args.win_length,\n                window=args.window,\n                fmin=args.fmin,\n                fmax=args.fmax,\n            )\n            writer[utt_id] = lmspc\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "utils/compute-fbank-feats.py"}], "after_files": [{"content": "#!/usr/bin/env python3\n\n# Copyright 2018 Nagoya University (Tomoki Hayashi)\n#  Apache 2.0  (http://www.apache.org/licenses/LICENSE-2.0)\n\nimport argparse\nfrom distutils.util import strtobool\nimport logging\n\nimport kaldiio\nimport numpy\nimport resampy\n\nfrom espnet.transform.spectrogram import logmelspectrogram\nfrom espnet.utils.cli_utils import get_commandline_args\nfrom espnet.utils.cli_writers import file_writer_helper\nfrom espnet2.utils.types import int_or_none\n\n\ndef get_parser():\n    parser = argparse.ArgumentParser(\n        description=\"compute FBANK feature from WAV\",\n        formatter_class=argparse.ArgumentDefaultsHelpFormatter,\n    )\n    parser.add_argument(\"--fs\", type=int_or_none, help=\"Sampling frequency\")\n    parser.add_argument(\n        \"--fmax\", type=int_or_none, default=None, nargs=\"?\", help=\"Maximum frequency\"\n    )\n    parser.add_argument(\n        \"--fmin\", type=int_or_none, default=None, nargs=\"?\", help=\"Minimum frequency\"\n    )\n    parser.add_argument(\"--n_mels\", type=int, default=80, help=\"Number of mel basis\")\n    parser.add_argument(\"--n_fft\", type=int, default=1024, help=\"FFT length in point\")\n    parser.add_argument(\n        \"--n_shift\", type=int, default=512, help=\"Shift length in point\"\n    )\n    parser.add_argument(\n        \"--win_length\",\n        type=int_or_none,\n        default=None,\n        nargs=\"?\",\n        help=\"Analisys window length in point\",\n    )\n    parser.add_argument(\n        \"--window\",\n        type=str,\n        default=\"hann\",\n        choices=[\"hann\", \"hamming\"],\n        help=\"Type of window\",\n    )\n    parser.add_argument(\n        \"--write-num-frames\", type=str, help=\"Specify wspecifer for utt2num_frames\"\n    )\n    parser.add_argument(\n        \"--filetype\",\n        type=str,\n        default=\"mat\",\n        choices=[\"mat\", \"hdf5\"],\n        help=\"Specify the file format for output. \"\n        '\"mat\" is the matrix format in kaldi',\n    )\n    parser.add_argument(\n        \"--compress\", type=strtobool, default=False, help=\"Save in compressed format\"\n    )\n    parser.add_argument(\n        \"--compression-method\",\n        type=int,\n        default=2,\n        help=\"Specify the method(if mat) or \" \"gzip-level(if hdf5)\",\n    )\n    parser.add_argument(\"--verbose\", \"-V\", default=0, type=int, help=\"Verbose option\")\n    parser.add_argument(\n        \"--normalize\",\n        choices=[1, 16, 24, 32],\n        type=int,\n        default=None,\n        help=\"Give the bit depth of the PCM, \"\n        \"then normalizes data to scale in [-1,1]\",\n    )\n    parser.add_argument(\"rspecifier\", type=str, help=\"WAV scp file\")\n    parser.add_argument(\n        \"--segments\",\n        type=str,\n        help=\"segments-file format: each line is either\"\n        \"<segment-id> <recording-id> <start-time> <end-time>\"\n        \"e.g. call-861225-A-0050-0065 call-861225-A 5.0 6.5\",\n    )\n    parser.add_argument(\"wspecifier\", type=str, help=\"Write specifier\")\n    return parser\n\n\ndef main():\n    parser = get_parser()\n    args = parser.parse_args()\n\n    logfmt = \"%(asctime)s (%(module)s:%(lineno)d) %(levelname)s: %(message)s\"\n    if args.verbose > 0:\n        logging.basicConfig(level=logging.INFO, format=logfmt)\n    else:\n        logging.basicConfig(level=logging.WARN, format=logfmt)\n    logging.info(get_commandline_args())\n\n    with kaldiio.ReadHelper(\n        args.rspecifier, segments=args.segments\n    ) as reader, file_writer_helper(\n        args.wspecifier,\n        filetype=args.filetype,\n        write_num_frames=args.write_num_frames,\n        compress=args.compress,\n        compression_method=args.compression_method,\n    ) as writer:\n        for utt_id, (rate, array) in reader:\n            array = array.astype(numpy.float32)\n            if args.fs is not None and rate != args.fs:\n                array = resampy.resample(array, rate, args.fs, axis=0)\n            if args.normalize is not None and args.normalize != 1:\n                array = array / (1 << (args.normalize - 1))\n\n            lmspc = logmelspectrogram(\n                x=array,\n                fs=args.fs if args.fs is not None else rate,\n                n_mels=args.n_mels,\n                n_fft=args.n_fft,\n                n_shift=args.n_shift,\n                win_length=args.win_length,\n                window=args.window,\n                fmin=args.fmin,\n                fmax=args.fmax,\n            )\n            writer[utt_id] = lmspc\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "utils/compute-fbank-feats.py"}]}