Alina Lozovskaya
commited on
Commit
·
37d00fb
1
Parent(s):
a6ddf4e
Fix mypy and enhance code clarity
Browse files
src/reachy_mini_conversation_app/openai_realtime.py
CHANGED
|
@@ -36,9 +36,14 @@ class OpenaiRealtimeHandler(AsyncStreamHandler):
|
|
| 36 |
"""Initialize the handler."""
|
| 37 |
super().__init__(
|
| 38 |
expected_layout="mono",
|
| 39 |
-
output_sample_rate=OPEN_AI_OUTPUT_SAMPLE_RATE,
|
| 40 |
-
input_sample_rate=OPEN_AI_INPUT_SAMPLE_RATE,
|
| 41 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
self.deps = deps
|
| 43 |
|
| 44 |
# Override type annotations for OpenAI strict typing (only for values used in API)
|
|
@@ -97,7 +102,7 @@ class OpenaiRealtimeHandler(AsyncStreamHandler):
|
|
| 97 |
"input": {
|
| 98 |
"format": {
|
| 99 |
"type": "audio/pcm",
|
| 100 |
-
"rate":
|
| 101 |
},
|
| 102 |
"transcription": {
|
| 103 |
"model": "whisper-1",
|
|
@@ -111,7 +116,7 @@ class OpenaiRealtimeHandler(AsyncStreamHandler):
|
|
| 111 |
"output": {
|
| 112 |
"format": {
|
| 113 |
"type": "audio/pcm",
|
| 114 |
-
"rate":
|
| 115 |
},
|
| 116 |
"voice": "cedar",
|
| 117 |
},
|
|
|
|
| 36 |
"""Initialize the handler."""
|
| 37 |
super().__init__(
|
| 38 |
expected_layout="mono",
|
| 39 |
+
output_sample_rate=OPEN_AI_OUTPUT_SAMPLE_RATE,
|
| 40 |
+
input_sample_rate=OPEN_AI_INPUT_SAMPLE_RATE,
|
| 41 |
)
|
| 42 |
+
|
| 43 |
+
# Override typing of the sample rates to match OpenAI's requirements
|
| 44 |
+
self.output_sample_rate: Literal[24000] = self.output_sample_rate
|
| 45 |
+
self.input_sample_rate: Literal[24000] = self.input_sample_rate
|
| 46 |
+
|
| 47 |
self.deps = deps
|
| 48 |
|
| 49 |
# Override type annotations for OpenAI strict typing (only for values used in API)
|
|
|
|
| 102 |
"input": {
|
| 103 |
"format": {
|
| 104 |
"type": "audio/pcm",
|
| 105 |
+
"rate": self.input_sample_rate,
|
| 106 |
},
|
| 107 |
"transcription": {
|
| 108 |
"model": "whisper-1",
|
|
|
|
| 116 |
"output": {
|
| 117 |
"format": {
|
| 118 |
"type": "audio/pcm",
|
| 119 |
+
"rate": self.output_sample_rate,
|
| 120 |
},
|
| 121 |
"voice": "cedar",
|
| 122 |
},
|