We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Encounter exception when running tools/compute_mean_std.py
```
Traceback (most recent call last):
  File "tools/compute_mean_std.py", line 64, in <module>
    main()
  File "tools/compute_mean_std.py", line 59, in main
    num_samples=args.num_samples)
  File "/home/disk1/yangyaming/workspace/paddle/ds2/mandarin_unicom/default_conf/tools/../data_utils/normalizer.py", line 46, in __init__
    self._compute_mean_std(manifest_path, featurize_func, num_samples)
  File "/home/disk1/yangyaming/workspace/paddle/ds2/mandarin_unicom/default_conf/tools/../data_utils/normalizer.py", line 84, in _compute_mean_std
    AudioSegment.from_file(instance["audio_filepath"])))
  File "tools/compute_mean_std.py", line 53, in augment_and_featurize
    return audio_featurizer.featurize(audio_segment)
  File "/home/disk1/yangyaming/workspace/paddle/ds2/mandarin_unicom/default_conf/tools/../data_utils/featurizer/audio_featurizer.py", line 79, in featurize
    allow_upsampling)):
NameError: global name 'allow_upsampling' is not defined
```
Look like a typo problem.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `deep_speech_2/data_utils/featurizer/audio_featurizer.py`
Content:
```
1 """Contains the audio featurizer class."""
2 from __future__ import absolute_import
3 from __future__ import division
4 from __future__ import print_function
5 
6 import numpy as np
7 from data_utils import utils
8 from data_utils.audio import AudioSegment
9 from python_speech_features import mfcc
10 from python_speech_features import delta
11 
12 
13 class AudioFeaturizer(object):
14     """Audio featurizer, for extracting features from audio contents of
15     AudioSegment or SpeechSegment.
16 
17     Currently, it supports feature types of linear spectrogram and mfcc.
18 
19     :param specgram_type: Specgram feature type. Options: 'linear'.
20     :type specgram_type: str
21     :param stride_ms: Striding size (in milliseconds) for generating frames.
22     :type stride_ms: float
23     :param window_ms: Window size (in milliseconds) for generating frames.
24     :type window_ms: float
25     :param max_freq: When specgram_type is 'linear', only FFT bins
26                      corresponding to frequencies between [0, max_freq] are
27                      returned; when specgram_type is 'mfcc', max_feq is the
28                      highest band edge of mel filters.
29     :types max_freq: None|float
30     :param target_sample_rate: Audio are resampled (if upsampling or
31                                downsampling is allowed) to this before
32                                extracting spectrogram features.
33     :type target_sample_rate: float
34     :param use_dB_normalization: Whether to normalize the audio to a certain
35                                  decibels before extracting the features.
36     :type use_dB_normalization: bool
37     :param target_dB: Target audio decibels for normalization.
38     :type target_dB: float
39     """
40 
41     def __init__(self,
42                  specgram_type='linear',
43                  stride_ms=10.0,
44                  window_ms=20.0,
45                  max_freq=None,
46                  target_sample_rate=16000,
47                  use_dB_normalization=True,
48                  target_dB=-20):
49         self._specgram_type = specgram_type
50         self._stride_ms = stride_ms
51         self._window_ms = window_ms
52         self._max_freq = max_freq
53         self._target_sample_rate = target_sample_rate
54         self._use_dB_normalization = use_dB_normalization
55         self._target_dB = target_dB
56 
57     def featurize(self,
58                   audio_segment,
59                   allow_downsampling=True,
60                   allow_upsamplling=True):
61         """Extract audio features from AudioSegment or SpeechSegment.
62 
63         :param audio_segment: Audio/speech segment to extract features from.
64         :type audio_segment: AudioSegment|SpeechSegment
65         :param allow_downsampling: Whether to allow audio downsampling before
66                                    featurizing.
67         :type allow_downsampling: bool
68         :param allow_upsampling: Whether to allow audio upsampling before
69                                  featurizing.
70         :type allow_upsampling: bool
71         :return: Spectrogram audio feature in 2darray.
72         :rtype: ndarray
73         :raises ValueError: If audio sample rate is not supported.
74         """
75         # upsampling or downsampling
76         if ((audio_segment.sample_rate > self._target_sample_rate and
77              allow_downsampling) or
78             (audio_segment.sample_rate < self._target_sample_rate and
79              allow_upsampling)):
80             audio_segment.resample(self._target_sample_rate)
81         if audio_segment.sample_rate != self._target_sample_rate:
82             raise ValueError("Audio sample rate is not supported. "
83                              "Turn allow_downsampling or allow up_sampling on.")
84         # decibel normalization
85         if self._use_dB_normalization:
86             audio_segment.normalize(target_db=self._target_dB)
87         # extract spectrogram
88         return self._compute_specgram(audio_segment.samples,
89                                       audio_segment.sample_rate)
90 
91     def _compute_specgram(self, samples, sample_rate):
92         """Extract various audio features."""
93         if self._specgram_type == 'linear':
94             return self._compute_linear_specgram(
95                 samples, sample_rate, self._stride_ms, self._window_ms,
96                 self._max_freq)
97         elif self._specgram_type == 'mfcc':
98             return self._compute_mfcc(samples, sample_rate, self._stride_ms,
99                                       self._window_ms, self._max_freq)
100         else:
101             raise ValueError("Unknown specgram_type %s. "
102                              "Supported values: linear." % self._specgram_type)
103 
104     def _compute_linear_specgram(self,
105                                  samples,
106                                  sample_rate,
107                                  stride_ms=10.0,
108                                  window_ms=20.0,
109                                  max_freq=None,
110                                  eps=1e-14):
111         """Compute the linear spectrogram from FFT energy."""
112         if max_freq is None:
113             max_freq = sample_rate / 2
114         if max_freq > sample_rate / 2:
115             raise ValueError("max_freq must be greater than half of "
116                              "sample rate.")
117         if stride_ms > window_ms:
118             raise ValueError("Stride size must not be greater than "
119                              "window size.")
120         stride_size = int(0.001 * sample_rate * stride_ms)
121         window_size = int(0.001 * sample_rate * window_ms)
122         specgram, freqs = self._specgram_real(
123             samples,
124             window_size=window_size,
125             stride_size=stride_size,
126             sample_rate=sample_rate)
127         ind = np.where(freqs <= max_freq)[0][-1] + 1
128         return np.log(specgram[:ind, :] + eps)
129 
130     def _specgram_real(self, samples, window_size, stride_size, sample_rate):
131         """Compute the spectrogram for samples from a real signal."""
132         # extract strided windows
133         truncate_size = (len(samples) - window_size) % stride_size
134         samples = samples[:len(samples) - truncate_size]
135         nshape = (window_size, (len(samples) - window_size) // stride_size + 1)
136         nstrides = (samples.strides[0], samples.strides[0] * stride_size)
137         windows = np.lib.stride_tricks.as_strided(
138             samples, shape=nshape, strides=nstrides)
139         assert np.all(
140             windows[:, 1] == samples[stride_size:(stride_size + window_size)])
141         # window weighting, squared Fast Fourier Transform (fft), scaling
142         weighting = np.hanning(window_size)[:, None]
143         fft = np.fft.rfft(windows * weighting, axis=0)
144         fft = np.absolute(fft)**2
145         scale = np.sum(weighting**2) * sample_rate
146         fft[1:-1, :] *= (2.0 / scale)
147         fft[(0, -1), :] /= scale
148         # prepare fft frequency list
149         freqs = float(sample_rate) / window_size * np.arange(fft.shape[0])
150         return fft, freqs
151 
152     def _compute_mfcc(self,
153                       samples,
154                       sample_rate,
155                       stride_ms=10.0,
156                       window_ms=20.0,
157                       max_freq=None):
158         """Compute mfcc from samples."""
159         if max_freq is None:
160             max_freq = sample_rate / 2
161         if max_freq > sample_rate / 2:
162             raise ValueError("max_freq must not be greater than half of "
163                              "sample rate.")
164         if stride_ms > window_ms:
165             raise ValueError("Stride size must not be greater than "
166                              "window size.")
167         # compute the 13 cepstral coefficients, and the first one is replaced
168         # by log(frame energy)
169         mfcc_feat = mfcc(
170             signal=samples,
171             samplerate=sample_rate,
172             winlen=0.001 * window_ms,
173             winstep=0.001 * stride_ms,
174             highfreq=max_freq)
175         # Deltas
176         d_mfcc_feat = delta(mfcc_feat, 2)
177         # Deltas-Deltas
178         dd_mfcc_feat = delta(d_mfcc_feat, 2)
179         # transpose
180         mfcc_feat = np.transpose(mfcc_feat)
181         d_mfcc_feat = np.transpose(d_mfcc_feat)
182         dd_mfcc_feat = np.transpose(dd_mfcc_feat)
183         # concat above three features
184         concat_mfcc_feat = np.concatenate(
185             (mfcc_feat, d_mfcc_feat, dd_mfcc_feat))
186         return concat_mfcc_feat
187
```
--- 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()

```

diff --git a/deep_speech_2/data_utils/featurizer/audio_featurizer.py b/deep_speech_2/data_utils/featurizer/audio_featurizer.py
--- a/deep_speech_2/data_utils/featurizer/audio_featurizer.py
+++ b/deep_speech_2/data_utils/featurizer/audio_featurizer.py
@@ -57,7 +57,7 @@
     def featurize(self,
                   audio_segment,
                   allow_downsampling=True,
-                  allow_upsamplling=True):
+                  allow_upsampling=True):
         """Extract audio features from AudioSegment or SpeechSegment.
 
         :param audio_segment: Audio/speech segment to extract features from.

{"golden_diff": "diff --git a/deep_speech_2/data_utils/featurizer/audio_featurizer.py b/deep_speech_2/data_utils/featurizer/audio_featurizer.py\n--- a/deep_speech_2/data_utils/featurizer/audio_featurizer.py\n+++ b/deep_speech_2/data_utils/featurizer/audio_featurizer.py\n@@ -57,7 +57,7 @@\n     def featurize(self,\n                   audio_segment,\n                   allow_downsampling=True,\n-                  allow_upsamplling=True):\n+                  allow_upsampling=True):\n         \"\"\"Extract audio features from AudioSegment or SpeechSegment.\n \n         :param audio_segment: Audio/speech segment to extract features from.\n", "issue": "Encounter exception when running tools/compute_mean_std.py\n```\r\nTraceback (most recent call last):\r\n  File \"tools/compute_mean_std.py\", line 64, in <module>\r\n    main()\r\n  File \"tools/compute_mean_std.py\", line 59, in main\r\n    num_samples=args.num_samples)\r\n  File \"/home/disk1/yangyaming/workspace/paddle/ds2/mandarin_unicom/default_conf/tools/../data_utils/normalizer.py\", line 46, in __init__\r\n    self._compute_mean_std(manifest_path, featurize_func, num_samples)\r\n  File \"/home/disk1/yangyaming/workspace/paddle/ds2/mandarin_unicom/default_conf/tools/../data_utils/normalizer.py\", line 84, in _compute_mean_std\r\n    AudioSegment.from_file(instance[\"audio_filepath\"])))\r\n  File \"tools/compute_mean_std.py\", line 53, in augment_and_featurize\r\n    return audio_featurizer.featurize(audio_segment)\r\n  File \"/home/disk1/yangyaming/workspace/paddle/ds2/mandarin_unicom/default_conf/tools/../data_utils/featurizer/audio_featurizer.py\", line 79, in featurize\r\n    allow_upsampling)):\r\nNameError: global name 'allow_upsampling' is not defined\r\n```\r\nLook like a typo problem.\n", "before_files": [{"content": "\"\"\"Contains the audio featurizer class.\"\"\"\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport numpy as np\nfrom data_utils import utils\nfrom data_utils.audio import AudioSegment\nfrom python_speech_features import mfcc\nfrom python_speech_features import delta\n\n\nclass AudioFeaturizer(object):\n    \"\"\"Audio featurizer, for extracting features from audio contents of\n    AudioSegment or SpeechSegment.\n\n    Currently, it supports feature types of linear spectrogram and mfcc.\n\n    :param specgram_type: Specgram feature type. Options: 'linear'.\n    :type specgram_type: str\n    :param stride_ms: Striding size (in milliseconds) for generating frames.\n    :type stride_ms: float\n    :param window_ms: Window size (in milliseconds) for generating frames.\n    :type window_ms: float\n    :param max_freq: When specgram_type is 'linear', only FFT bins\n                     corresponding to frequencies between [0, max_freq] are\n                     returned; when specgram_type is 'mfcc', max_feq is the\n                     highest band edge of mel filters.\n    :types max_freq: None|float\n    :param target_sample_rate: Audio are resampled (if upsampling or\n                               downsampling is allowed) to this before\n                               extracting spectrogram features.\n    :type target_sample_rate: float\n    :param use_dB_normalization: Whether to normalize the audio to a certain\n                                 decibels before extracting the features.\n    :type use_dB_normalization: bool\n    :param target_dB: Target audio decibels for normalization.\n    :type target_dB: float\n    \"\"\"\n\n    def __init__(self,\n                 specgram_type='linear',\n                 stride_ms=10.0,\n                 window_ms=20.0,\n                 max_freq=None,\n                 target_sample_rate=16000,\n                 use_dB_normalization=True,\n                 target_dB=-20):\n        self._specgram_type = specgram_type\n        self._stride_ms = stride_ms\n        self._window_ms = window_ms\n        self._max_freq = max_freq\n        self._target_sample_rate = target_sample_rate\n        self._use_dB_normalization = use_dB_normalization\n        self._target_dB = target_dB\n\n    def featurize(self,\n                  audio_segment,\n                  allow_downsampling=True,\n                  allow_upsamplling=True):\n        \"\"\"Extract audio features from AudioSegment or SpeechSegment.\n\n        :param audio_segment: Audio/speech segment to extract features from.\n        :type audio_segment: AudioSegment|SpeechSegment\n        :param allow_downsampling: Whether to allow audio downsampling before\n                                   featurizing.\n        :type allow_downsampling: bool\n        :param allow_upsampling: Whether to allow audio upsampling before\n                                 featurizing.\n        :type allow_upsampling: bool\n        :return: Spectrogram audio feature in 2darray.\n        :rtype: ndarray\n        :raises ValueError: If audio sample rate is not supported.\n        \"\"\"\n        # upsampling or downsampling\n        if ((audio_segment.sample_rate > self._target_sample_rate and\n             allow_downsampling) or\n            (audio_segment.sample_rate < self._target_sample_rate and\n             allow_upsampling)):\n            audio_segment.resample(self._target_sample_rate)\n        if audio_segment.sample_rate != self._target_sample_rate:\n            raise ValueError(\"Audio sample rate is not supported. \"\n                             \"Turn allow_downsampling or allow up_sampling on.\")\n        # decibel normalization\n        if self._use_dB_normalization:\n            audio_segment.normalize(target_db=self._target_dB)\n        # extract spectrogram\n        return self._compute_specgram(audio_segment.samples,\n                                      audio_segment.sample_rate)\n\n    def _compute_specgram(self, samples, sample_rate):\n        \"\"\"Extract various audio features.\"\"\"\n        if self._specgram_type == 'linear':\n            return self._compute_linear_specgram(\n                samples, sample_rate, self._stride_ms, self._window_ms,\n                self._max_freq)\n        elif self._specgram_type == 'mfcc':\n            return self._compute_mfcc(samples, sample_rate, self._stride_ms,\n                                      self._window_ms, self._max_freq)\n        else:\n            raise ValueError(\"Unknown specgram_type %s. \"\n                             \"Supported values: linear.\" % self._specgram_type)\n\n    def _compute_linear_specgram(self,\n                                 samples,\n                                 sample_rate,\n                                 stride_ms=10.0,\n                                 window_ms=20.0,\n                                 max_freq=None,\n                                 eps=1e-14):\n        \"\"\"Compute the linear spectrogram from FFT energy.\"\"\"\n        if max_freq is None:\n            max_freq = sample_rate / 2\n        if max_freq > sample_rate / 2:\n            raise ValueError(\"max_freq must be greater than half of \"\n                             \"sample rate.\")\n        if stride_ms > window_ms:\n            raise ValueError(\"Stride size must not be greater than \"\n                             \"window size.\")\n        stride_size = int(0.001 * sample_rate * stride_ms)\n        window_size = int(0.001 * sample_rate * window_ms)\n        specgram, freqs = self._specgram_real(\n            samples,\n            window_size=window_size,\n            stride_size=stride_size,\n            sample_rate=sample_rate)\n        ind = np.where(freqs <= max_freq)[0][-1] + 1\n        return np.log(specgram[:ind, :] + eps)\n\n    def _specgram_real(self, samples, window_size, stride_size, sample_rate):\n        \"\"\"Compute the spectrogram for samples from a real signal.\"\"\"\n        # extract strided windows\n        truncate_size = (len(samples) - window_size) % stride_size\n        samples = samples[:len(samples) - truncate_size]\n        nshape = (window_size, (len(samples) - window_size) // stride_size + 1)\n        nstrides = (samples.strides[0], samples.strides[0] * stride_size)\n        windows = np.lib.stride_tricks.as_strided(\n            samples, shape=nshape, strides=nstrides)\n        assert np.all(\n            windows[:, 1] == samples[stride_size:(stride_size + window_size)])\n        # window weighting, squared Fast Fourier Transform (fft), scaling\n        weighting = np.hanning(window_size)[:, None]\n        fft = np.fft.rfft(windows * weighting, axis=0)\n        fft = np.absolute(fft)**2\n        scale = np.sum(weighting**2) * sample_rate\n        fft[1:-1, :] *= (2.0 / scale)\n        fft[(0, -1), :] /= scale\n        # prepare fft frequency list\n        freqs = float(sample_rate) / window_size * np.arange(fft.shape[0])\n        return fft, freqs\n\n    def _compute_mfcc(self,\n                      samples,\n                      sample_rate,\n                      stride_ms=10.0,\n                      window_ms=20.0,\n                      max_freq=None):\n        \"\"\"Compute mfcc from samples.\"\"\"\n        if max_freq is None:\n            max_freq = sample_rate / 2\n        if max_freq > sample_rate / 2:\n            raise ValueError(\"max_freq must not be greater than half of \"\n                             \"sample rate.\")\n        if stride_ms > window_ms:\n            raise ValueError(\"Stride size must not be greater than \"\n                             \"window size.\")\n        # compute the 13 cepstral coefficients, and the first one is replaced\n        # by log(frame energy)\n        mfcc_feat = mfcc(\n            signal=samples,\n            samplerate=sample_rate,\n            winlen=0.001 * window_ms,\n            winstep=0.001 * stride_ms,\n            highfreq=max_freq)\n        # Deltas\n        d_mfcc_feat = delta(mfcc_feat, 2)\n        # Deltas-Deltas\n        dd_mfcc_feat = delta(d_mfcc_feat, 2)\n        # transpose\n        mfcc_feat = np.transpose(mfcc_feat)\n        d_mfcc_feat = np.transpose(d_mfcc_feat)\n        dd_mfcc_feat = np.transpose(dd_mfcc_feat)\n        # concat above three features\n        concat_mfcc_feat = np.concatenate(\n            (mfcc_feat, d_mfcc_feat, dd_mfcc_feat))\n        return concat_mfcc_feat\n", "path": "deep_speech_2/data_utils/featurizer/audio_featurizer.py"}], "after_files": [{"content": "\"\"\"Contains the audio featurizer class.\"\"\"\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport numpy as np\nfrom data_utils import utils\nfrom data_utils.audio import AudioSegment\nfrom python_speech_features import mfcc\nfrom python_speech_features import delta\n\n\nclass AudioFeaturizer(object):\n    \"\"\"Audio featurizer, for extracting features from audio contents of\n    AudioSegment or SpeechSegment.\n\n    Currently, it supports feature types of linear spectrogram and mfcc.\n\n    :param specgram_type: Specgram feature type. Options: 'linear'.\n    :type specgram_type: str\n    :param stride_ms: Striding size (in milliseconds) for generating frames.\n    :type stride_ms: float\n    :param window_ms: Window size (in milliseconds) for generating frames.\n    :type window_ms: float\n    :param max_freq: When specgram_type is 'linear', only FFT bins\n                     corresponding to frequencies between [0, max_freq] are\n                     returned; when specgram_type is 'mfcc', max_feq is the\n                     highest band edge of mel filters.\n    :types max_freq: None|float\n    :param target_sample_rate: Audio are resampled (if upsampling or\n                               downsampling is allowed) to this before\n                               extracting spectrogram features.\n    :type target_sample_rate: float\n    :param use_dB_normalization: Whether to normalize the audio to a certain\n                                 decibels before extracting the features.\n    :type use_dB_normalization: bool\n    :param target_dB: Target audio decibels for normalization.\n    :type target_dB: float\n    \"\"\"\n\n    def __init__(self,\n                 specgram_type='linear',\n                 stride_ms=10.0,\n                 window_ms=20.0,\n                 max_freq=None,\n                 target_sample_rate=16000,\n                 use_dB_normalization=True,\n                 target_dB=-20):\n        self._specgram_type = specgram_type\n        self._stride_ms = stride_ms\n        self._window_ms = window_ms\n        self._max_freq = max_freq\n        self._target_sample_rate = target_sample_rate\n        self._use_dB_normalization = use_dB_normalization\n        self._target_dB = target_dB\n\n    def featurize(self,\n                  audio_segment,\n                  allow_downsampling=True,\n                  allow_upsampling=True):\n        \"\"\"Extract audio features from AudioSegment or SpeechSegment.\n\n        :param audio_segment: Audio/speech segment to extract features from.\n        :type audio_segment: AudioSegment|SpeechSegment\n        :param allow_downsampling: Whether to allow audio downsampling before\n                                   featurizing.\n        :type allow_downsampling: bool\n        :param allow_upsampling: Whether to allow audio upsampling before\n                                 featurizing.\n        :type allow_upsampling: bool\n        :return: Spectrogram audio feature in 2darray.\n        :rtype: ndarray\n        :raises ValueError: If audio sample rate is not supported.\n        \"\"\"\n        # upsampling or downsampling\n        if ((audio_segment.sample_rate > self._target_sample_rate and\n             allow_downsampling) or\n            (audio_segment.sample_rate < self._target_sample_rate and\n             allow_upsampling)):\n            audio_segment.resample(self._target_sample_rate)\n        if audio_segment.sample_rate != self._target_sample_rate:\n            raise ValueError(\"Audio sample rate is not supported. \"\n                             \"Turn allow_downsampling or allow up_sampling on.\")\n        # decibel normalization\n        if self._use_dB_normalization:\n            audio_segment.normalize(target_db=self._target_dB)\n        # extract spectrogram\n        return self._compute_specgram(audio_segment.samples,\n                                      audio_segment.sample_rate)\n\n    def _compute_specgram(self, samples, sample_rate):\n        \"\"\"Extract various audio features.\"\"\"\n        if self._specgram_type == 'linear':\n            return self._compute_linear_specgram(\n                samples, sample_rate, self._stride_ms, self._window_ms,\n                self._max_freq)\n        elif self._specgram_type == 'mfcc':\n            return self._compute_mfcc(samples, sample_rate, self._stride_ms,\n                                      self._window_ms, self._max_freq)\n        else:\n            raise ValueError(\"Unknown specgram_type %s. \"\n                             \"Supported values: linear.\" % self._specgram_type)\n\n    def _compute_linear_specgram(self,\n                                 samples,\n                                 sample_rate,\n                                 stride_ms=10.0,\n                                 window_ms=20.0,\n                                 max_freq=None,\n                                 eps=1e-14):\n        \"\"\"Compute the linear spectrogram from FFT energy.\"\"\"\n        if max_freq is None:\n            max_freq = sample_rate / 2\n        if max_freq > sample_rate / 2:\n            raise ValueError(\"max_freq must be greater than half of \"\n                             \"sample rate.\")\n        if stride_ms > window_ms:\n            raise ValueError(\"Stride size must not be greater than \"\n                             \"window size.\")\n        stride_size = int(0.001 * sample_rate * stride_ms)\n        window_size = int(0.001 * sample_rate * window_ms)\n        specgram, freqs = self._specgram_real(\n            samples,\n            window_size=window_size,\n            stride_size=stride_size,\n            sample_rate=sample_rate)\n        ind = np.where(freqs <= max_freq)[0][-1] + 1\n        return np.log(specgram[:ind, :] + eps)\n\n    def _specgram_real(self, samples, window_size, stride_size, sample_rate):\n        \"\"\"Compute the spectrogram for samples from a real signal.\"\"\"\n        # extract strided windows\n        truncate_size = (len(samples) - window_size) % stride_size\n        samples = samples[:len(samples) - truncate_size]\n        nshape = (window_size, (len(samples) - window_size) // stride_size + 1)\n        nstrides = (samples.strides[0], samples.strides[0] * stride_size)\n        windows = np.lib.stride_tricks.as_strided(\n            samples, shape=nshape, strides=nstrides)\n        assert np.all(\n            windows[:, 1] == samples[stride_size:(stride_size + window_size)])\n        # window weighting, squared Fast Fourier Transform (fft), scaling\n        weighting = np.hanning(window_size)[:, None]\n        fft = np.fft.rfft(windows * weighting, axis=0)\n        fft = np.absolute(fft)**2\n        scale = np.sum(weighting**2) * sample_rate\n        fft[1:-1, :] *= (2.0 / scale)\n        fft[(0, -1), :] /= scale\n        # prepare fft frequency list\n        freqs = float(sample_rate) / window_size * np.arange(fft.shape[0])\n        return fft, freqs\n\n    def _compute_mfcc(self,\n                      samples,\n                      sample_rate,\n                      stride_ms=10.0,\n                      window_ms=20.0,\n                      max_freq=None):\n        \"\"\"Compute mfcc from samples.\"\"\"\n        if max_freq is None:\n            max_freq = sample_rate / 2\n        if max_freq > sample_rate / 2:\n            raise ValueError(\"max_freq must not be greater than half of \"\n                             \"sample rate.\")\n        if stride_ms > window_ms:\n            raise ValueError(\"Stride size must not be greater than \"\n                             \"window size.\")\n        # compute the 13 cepstral coefficients, and the first one is replaced\n        # by log(frame energy)\n        mfcc_feat = mfcc(\n            signal=samples,\n            samplerate=sample_rate,\n            winlen=0.001 * window_ms,\n            winstep=0.001 * stride_ms,\n            highfreq=max_freq)\n        # Deltas\n        d_mfcc_feat = delta(mfcc_feat, 2)\n        # Deltas-Deltas\n        dd_mfcc_feat = delta(d_mfcc_feat, 2)\n        # transpose\n        mfcc_feat = np.transpose(mfcc_feat)\n        d_mfcc_feat = np.transpose(d_mfcc_feat)\n        dd_mfcc_feat = np.transpose(dd_mfcc_feat)\n        # concat above three features\n        concat_mfcc_feat = np.concatenate(\n            (mfcc_feat, d_mfcc_feat, dd_mfcc_feat))\n        return concat_mfcc_feat\n", "path": "deep_speech_2/data_utils/featurizer/audio_featurizer.py"}]}