2

我正在尝试了解代码为 VGGish 所做的事情,但我遇到了一个我不太了解的部分。在 vggish_input.py 中有这样的:

def wavfile_to_examples(wav_file):
  """Convenience wrapper around waveform_to_examples() for a common WAV format.
  Args:
    wav_file: String path to a file, or a file-like object. The file
    is assumed to contain WAV audio data with signed 16-bit PCM samples.
  Returns:
    See waveform_to_examples.
  """
  wav_data, sr = wav_read(wav_file)
  assert wav_data.dtype == np.int16, 'Bad sample type: %r' % wav_data.dtype
  samples = wav_data / 32768.0  # Convert to [-1.0, +1.0]
  return waveform_to_examples(samples, sr)

32768 的常数从何而来,如何除以将数据转换为样本?

我发现它可以转换为 -1 和 +1,但不确定如何将其与 32768 连接起来。

https://stats.stackexchange.com/questions/178626/how-to-normalize-data-between-1-and-1

4

1 回答 1

2

32768 是 2^15。int16 的范围是 -32768 到 +32767。如果您将 int16 作为输入并将其除以 2^15,您将得到一个介于 -1 和 +1 之间的数字。

于 2021-03-23T12:16:05.637 回答