audio_splitter.py 581 B

12345678910111213141516171819
  1. from pydub import AudioSegment
  2. from pydub.silence import split_on_silence
  3. # https://stackoverflow.com/questions/36458214/split-speech-audio-file-on-words-in-python
  4. sound_file = AudioSegment.from_wav("output.wav")
  5. audio_chunks = split_on_silence(sound_file,
  6. # must be silent for at least half a second
  7. min_silence_len=200,
  8. # consider it silent if quieter than -16 dBFS
  9. silence_thresh=-16
  10. )
  11. for i, chunk in enumerate(audio_chunks):
  12. out_file = ".//splitAudio//chunk{0}.wav".format(i)
  13. print ("exporting", out_file)
  14. chunk.export(out_file, format="wav")