Skip to content

Commit

Permalink
make asdict method for utterance class
Browse files Browse the repository at this point in the history
  • Loading branch information
bvreede committed Nov 1, 2023
1 parent 9b4657c commit aafde08
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sktalk/corpus/conversation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import json
from dataclasses import asdict


class Conversation:
def __init__(
Expand Down Expand Up @@ -46,6 +46,12 @@ def summarize(self):
for utterance in self._utterances[:10]:
print(utterance)

def asdict(self):
utt_list = [u.asdict() for u in self._utterances]
conv_dict = self._metadata.copy()
conv_dict["Conversation"] = utt_list
return conv_dict

def write_json(self, name, directory):
"""
Write a conversation to a JSONL file.
Expand All @@ -58,7 +64,7 @@ def write_json(self, name, directory):
name = f"{name}.jsonl"
destination = os.path.join(directory, name)

utt_list = [asdict(u) for u in self._utterances]
utt_list = [u.asdict() for u in self._utterances]
conv_dict = self._metadata.copy()
conv_dict["Conversation"] = utt_list

Expand Down
2 changes: 2 additions & 0 deletions sktalk/corpus/utterance.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Utterance:
def get_audio(self):
pass

def asdict(self):
return asdict(self)

# TODO function: that prints summary of data, shows it to user
# TODO function: create a pandas data frame with the utterances

0 comments on commit aafde08

Please sign in to comment.