save_wav with a custom sampling rate

This commit is contained in:
Eren Gölge 2021-02-11 15:27:20 +00:00 committed by Eren Gölge
parent 9fefc79f0c
commit 00e0933f43
2 changed files with 4 additions and 3 deletions

View File

@ -219,7 +219,7 @@ def main():
str.maketrans('', '', string.punctuation.replace('_', ''))) + '.wav'
out_path = os.path.join(args.out_path, file_name)
print(" > Saving output to {}".format(out_path))
synthesizer.save_wav(wav, out_path)
synthesizer.save_wav(wav, out_path,)
if __name__ == "__main__":

View File

@ -342,9 +342,10 @@ class AudioProcessor(object):
x = self.sound_norm(x)
return x
def save_wav(self, wav, path):
def save_wav(self, wav, path, sample_rate=None):
sample_rate = self.sample_rate if sample_rate is None else sample_rate
wav_norm = wav * (32767 / max(0.01, np.max(np.abs(wav))))
scipy.io.wavfile.write(path, self.sample_rate, wav_norm.astype(np.int16))
scipy.io.wavfile.write(path, sample_rate, wav_norm.astype(np.int16))
@staticmethod
def mulaw_encode(wav, qc):