/
conversation.py
36 lines (27 loc) · 1.11 KB
/
conversation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from minutes.audio import Audio
class Phrase:
def __init__(self, observation, speaker):
"""A phrase in a conversation, characterized by an audio segment
and a speaker.
Arguments:
observation {np.array} -- 1 dimensional audio sample.
speaker {Speaker} -- The inferred speaker for the audio segment.
"""
self.observation = observation
self.speaker = speaker
class Conversation(Audio):
def __init__(self, audio_loc, model):
"""Create a new conversation from audio sample.
Arguments:
audio_loc {str} -- The absolute location of an audio conversation
sample.
model {Minutes} -- A model trained on speakers within this
conversation.
"""
self.model = model
super().__init__(audio_loc)
# Predict against the conversation spectrograms.
raw, X_hat = self.get_observations(**model.preprocessing_params)
y_hat = model.predict(X_hat)
# Convert to a list of phrases.
self.phrases = [Phrase(o, speaker) for o, speaker in zip(raw, y_hat)]