How to split the audio file in python

Anagha picture Anagha · Apr 4, 2017 · Viewed 16.5k times · Source

I'am working on Speech sentiment analysis on customer care data. I have an audio file where the customer care official has asked the question and the customer has given his review.

I need to split this audio, and get only the review part from the customer to do sentiment analysis, whether the customer is happy, sad or neutral.

Please let me know, how to split audio file to get only the audio of the customer. The audio is in the format ".aac"

So far this is what i have done:

from os import path
AUDIO_FILE = path.join(path.dirname(path.realpath('C:\\Users\\anagha\\Documents\\Python Scripts')),"Python Scripts\\audioa.aac")

halfway_point = len(AUDIO_FILE) / 2

Answer

Jiaaro picture Jiaaro · Apr 6, 2017

since you used the pydub tag, here's how to do it with pydub

from pydub import AudioSegment
sound = AudioSegment.from_file(AUDIO_FILE)

halfway_point = len(sound) // 2
first_half = sound[:halfway_point]

# create a new file "first_half.mp3":
first_half.export("/path/to/first_half.mp3", format="mp3")