CopyPastor

Detecting plagiarism made easy.

Score: 0.8104824773582494; Reported for: String similarity Open both answers

Original Post

Original - Posted on 2023-11-03
by Anna Andreeva Rogotulka



            
Present in both answers; Present only in the new answer; Present only in the old answer;

you can use `librosa`, the task is to split array on chunks which size exactly equals sample rate multimplies 5 seconds
import librosa import soundfile as sf audio_file = "example.mp3" y, sr = librosa.load(audio_file, sr=None) # chunk duration 5 seconds chunk_duration = 5 chunk_samples = int(chunk_duration * sr) chunks = [y[i:i + chunk_samples] for i in range(0, len(y), chunk_samples)] for i, chunk in enumerate(chunks): output_file = f"chunk_{i}.mp3" sf.write(output_file, chunk, sr)
you can split array in chunks just using index spliting, in order to get 2 seconds you need 2 * sample rate values from array and then step ahead
import librosa import soundfile as sf audio_file = "0.wav" y, sr = librosa.load(audio_file, sr=None) # chunk duration 2 seconds chunk_duration = 2 chunk_samples = int(chunk_duration * sr) chunks = [y[i:i + chunk_samples] for i in range(0, len(y), chunk_samples)] for i, chunk in enumerate(chunks): output_file = f"chunk_{i}.wav" sf.write(output_file, chunk, sr)

        
Present in both answers; Present only in the new answer; Present only in the old answer;