Skip to content

Commit 0275be1

Browse files
committed
Apply code formatting to audio nodes
1 parent 6f383bc commit 0275be1

File tree

5 files changed

+23
-28
lines changed

5 files changed

+23
-28
lines changed

ros/angel_system_nodes/angel_system_nodes/audio/asr.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ def __init__(self):
106106
self.subscription = self.create_subscription(
107107
HeadsetAudioData, self._audio_topic, self.listener_callback, 1
108108
)
109-
self._publisher = self.create_publisher(DialogueUtterance,
110-
self._utterances_topic, 1)
109+
self._publisher = self.create_publisher(
110+
DialogueUtterance, self._utterances_topic, 1
111+
)
111112

112113
self.audio_stream = []
113114
self.t = threading.Thread()
@@ -204,18 +205,15 @@ def asr_server_request_thread(self, audio_data, num_channels, sample_rate):
204205
if response:
205206
response_text = json.loads(response.text)["text"]
206207
self.log.info("Complete ASR text is:\n" + f'"{response_text}"')
207-
self._publish_response(response_text,
208-
self._is_sentence_tokenize_mode)
208+
self._publish_response(response_text, self._is_sentence_tokenize_mode)
209209

210210
def _publish_response(self, response_text: str, tokenize_sentences: bool):
211211
if tokenize_sentences:
212212
for sentence in sent_tokenize(response_text):
213-
self._publisher.publish(
214-
self._construct_dialogue_utterance(sentence))
213+
self._publisher.publish(self._construct_dialogue_utterance(sentence))
215214
else:
216-
self._publisher.publish(
217-
self._construct_dialogue_utterance(response_text))
218-
215+
self._publisher.publish(self._construct_dialogue_utterance(response_text))
216+
219217
def _construct_dialogue_utterance(self, msg_text: str) -> DialogueUtterance:
220218
msg = DialogueUtterance()
221219
msg.header.frame_id = "ASR"
@@ -225,7 +223,6 @@ def _construct_dialogue_utterance(self, msg_text: str) -> DialogueUtterance:
225223
return msg
226224

227225

228-
229226
main = make_default_main(ASR)
230227

231228

ros/angel_system_nodes/angel_system_nodes/audio/dialogue_utterance_processing.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from angel_msgs.msg import DialogueUtterance
22

3-
def copy_dialogue_utterance(msg: DialogueUtterance,
4-
node_name,
5-
copy_time) -> DialogueUtterance:
3+
4+
def copy_dialogue_utterance(
5+
msg: DialogueUtterance, node_name, copy_time
6+
) -> DialogueUtterance:
67
msg = DialogueUtterance()
78
msg.header.frame_id = node_name
89
msg.utterance_text = msg.utterance_text

ros/angel_system_nodes/angel_system_nodes/audio/emotion/base_emotion_detector.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ def __init__(self):
5353
self.emotion_detection_callback,
5454
1,
5555
)
56-
self._publication = self.create_publisher(
57-
DialogueUtterance, self._out_topic, 1
58-
)
56+
self._publication = self.create_publisher(DialogueUtterance, self._out_topic, 1)
5957

6058
self.message_queue = queue.Queue()
6159
self.handler_thread = threading.Thread(target=self.process_message_queue)
@@ -119,8 +117,10 @@ def process_message(self, msg: DialogueUtterance):
119117
"""
120118
classification, confidence_score = self.get_inference(msg)
121119
pub_msg = dialogue_utterance_processing.copy_dialogue_utterance(
122-
msg, node_name="Emotion Detection",
123-
copy_time=self.get_clock().now().to_msg())
120+
msg,
121+
node_name="Emotion Detection",
122+
copy_time=self.get_clock().now().to_msg(),
123+
)
124124
# Overwrite the user emotion with the latest classification information.
125125
pub_msg.emotion = classification
126126
pub_msg.emotion_confidence_score = confidence_score

ros/angel_system_nodes/angel_system_nodes/audio/intent/base_intent_detector.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -110,30 +110,27 @@ def _tiebreak_intents(intents, confidences):
110110

111111
if not intents:
112112
colored_utterance = colored(msg.utterance_text, "light_blue")
113-
self.log.info(
114-
f'No intents detected for:\n>>> "{colored_utterance}":')
113+
self.log.info(f'No intents detected for:\n>>> "{colored_utterance}":')
115114
return None, -1.0
116115
else:
117116
classification, confidence = _tiebreak_intents(intents, confidences)
118117
classification = colored(classification, "light_green")
119118
self.publish_message(msg.utterance_text, classification, confidence)
120119

121-
def publish_message(self, msg: DialogueUtterance, intent: str,
122-
score: float):
120+
def publish_message(self, msg: DialogueUtterance, intent: str, score: float):
123121
"""
124122
Handles message publishing for an utterance with a detected intent.
125123
"""
126124
pub_msg = self.copy_dialogue_utterance(
127-
msg, node_name="Intent Detection",
128-
copy_time=self.get_clock().now().to_msg())
125+
msg, node_name="Intent Detection", copy_time=self.get_clock().now().to_msg()
126+
)
129127
# Overwrite the user intent with the latest classification information.
130128
pub_msg.intent = intent
131129
pub_msg.intent_confidence_score = score
132130

133131
# Decide which intent topic to publish the message to.
134132
published_topic = None
135-
if self._contains_phrase(pub_msg.utterance_text.lower(),
136-
OVERRIDE_KEYPHRASES):
133+
if self._contains_phrase(pub_msg.utterance_text.lower(), OVERRIDE_KEYPHRASES):
137134
published_topic = PARAM_EXPECT_USER_INTENT_TOPIC
138135
pub_msg.intent_confidence_score = 1.0
139136
self._expected_publisher.publish(pub_msg)

ros/angel_system_nodes/angel_system_nodes/audio/intent/gpt_intent_detector.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from angel_utils import declare_and_get_parameters, make_default_main
1414

1515

16-
1716
openai.organization = os.getenv("OPENAI_ORG_ID")
1817
openai.api_key = os.getenv("OPENAI_API_KEY")
1918

@@ -28,6 +27,7 @@
2827

2928
PARAM_TIMEOUT = "timeout"
3029

30+
3131
class GptIntentDetector(BaseIntentDetector):
3232
def __init__(self):
3333
super().__init__()
@@ -100,7 +100,7 @@ def detect_intents(self, msg: DialogueUtterance):
100100
Detects the user intent via langchain execution of GPT.
101101
"""
102102
intent = self.chain.run(utterance=msg.utterance_text)
103-
return intent.split('[eos]')[0], 0.5
103+
return intent.split("[eos]")[0], 0.5
104104

105105

106106
main = make_default_main(GptIntentDetector)

0 commit comments

Comments
 (0)