In [2]:
# import Speaker Recognition File
import GmmSpeakerRec as GSR
# import librosa for audio loading
import librosa
# import Ipython for display the audio content
from IPython.display import display, Audio

In [3]:
# Create a new recognizer and enroll training data for male and female voices
Gender = GSR.GMMRec()
audio_path = './Audio/male.wav'
y_male, sr = librosa.load(audio_path, sr = 44100)
Gender.enroll('Male', y_male)
audio_path = './Audio/female.wav'
y_female, sr = librosa.load(audio_path, sr = 44100)
Gender.enroll('Female', y_female)

In [4]:
# Train the recognition model
Gender.train()

In [5]:
# Save the model to a local file
Gender.dump('gender.model')

In [6]:
# Load the testing audio
audio_path = './Audio/female-male.wav'
y_test, sr = librosa.load(audio_path, sr = 44100)
# Play the testing audio
display(Audio(data = y_test, rate = sr))
# Run recognition algorithm on the testing audio
Gender.recognize(y_test, step = 5, duration = 5, disp = False)


Recognition results:
0:00:00 Male
0:00:05 Male
0:00:10 Male
0:00:15 Male
0:00:20 Male
0:00:25 Female
0:00:30 Female
0:00:35 Female
0:00:40 Female
0:00:45 Female
0:00:50 Female
0:00:55 Female
0:01:00 Female
0:01:05 Male
0:01:10 Male
0:01:15 Male
0:01:20 Male
0:01:25 Male
0:01:30 Female
0:01:35 Male
0:01:40 Male
0:01:45 Male
0:01:50 Male
0:01:55 Male
0:02:00 Male
0:02:05 Female
0:02:10 Female
0:02:15 Female

In [ ]: