vocal-cli 0.3.8__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,8 +27,7 @@ venv/
27
27
  ENV/
28
28
  env/
29
29
 
30
- # UV
31
- uv.lock
30
+ # UV (uv.lock is committed for reproducible builds)
32
31
 
33
32
  # IDE
34
33
  .vscode/
@@ -1,3 +1,3 @@
1
- include ../../../README.md
2
- include ../../../LICENSE
3
- recursive-include vocal_cli *.py
1
+ include ../../../README.md
2
+ include ../../../LICENSE
3
+ recursive-include vocal_cli *.py
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: vocal-cli
3
- Version: 0.3.8
3
+ Version: 0.4.0
4
4
  Summary: CLI tool for Vocal - Ollama-style Voice Model Management
5
5
  Project-URL: Homepage, https://github.com/niradler/vocal
6
6
  Project-URL: Documentation, https://github.com/niradler/vocal/tree/master/docs
@@ -19,10 +19,10 @@ Classifier: Programming Language :: Python :: 3.13
19
19
  Classifier: Topic :: Utilities
20
20
  Requires-Python: >=3.11
21
21
  Requires-Dist: numpy>=2.4.3
22
- Requires-Dist: rich>=14.3.3
23
- Requires-Dist: sounddevice>=0.5.5
24
- Requires-Dist: typer>=0.24.1
25
- Requires-Dist: uvicorn>=0.41.0
26
- Requires-Dist: vocal-core>=0.3.8
27
- Requires-Dist: vocal-sdk>=0.3.8
28
- Requires-Dist: websockets>=16.0
22
+ Requires-Dist: rich>=15.0.0
23
+ Requires-Dist: sounddevice>=0.5.6
24
+ Requires-Dist: typer<0.28,>=0.27.3
25
+ Requires-Dist: uvicorn>=0.54.0
26
+ Requires-Dist: vocal-core>=0.4.0
27
+ Requires-Dist: vocal-sdk>=0.4.0
28
+ Requires-Dist: websockets>=17.4
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "vocal-cli"
3
- version = "0.3.8"
3
+ version = "0.4.0"
4
4
  description = "CLI tool for Vocal - Ollama-style Voice Model Management"
5
5
  requires-python = ">=3.11"
6
6
  license = { text = "SSPL-1.0" }
@@ -19,14 +19,14 @@ classifiers = [
19
19
  "Topic :: Utilities",
20
20
  ]
21
21
  dependencies = [
22
- "vocal-core>=0.3.8",
23
- "vocal-sdk>=0.3.8",
24
- "typer>=0.24.1",
25
- "rich>=14.3.3",
26
- "uvicorn>=0.41.0",
27
- "sounddevice>=0.5.5",
22
+ "vocal-core>=0.4.0",
23
+ "vocal-sdk>=0.4.0",
24
+ "typer>=0.27.3,<0.28",
25
+ "rich>=15.0.0",
26
+ "uvicorn>=0.54.0",
27
+ "sounddevice>=0.5.6",
28
28
  "numpy>=2.4.3",
29
- "websockets>=16.0",
29
+ "websockets>=17.4",
30
30
  ]
31
31
 
32
32
  [project.urls]
@@ -4,4 +4,4 @@ Vocal CLI - Command-line interface for Vocal Speech AI Platform
4
4
  This CLI provides Ollama-style commands for model management and audio transcription.
5
5
  """
6
6
 
7
- __version__ = "0.3.8"
7
+ __version__ = "0.4.0"
@@ -1084,6 +1084,77 @@ def _play_wav_bytes(audio_bytes: bytes, device: int | None = None) -> None:
1084
1084
  sd.wait()
1085
1085
 
1086
1086
 
1087
+ class _StreamingPlayback:
1088
+ """Plays PCM16 chunks as they arrive instead of waiting for a whole reply."""
1089
+
1090
+ def __init__(self, device: int | None, sample_rate: int = 24000) -> None:
1091
+ self._device = device
1092
+ self._rate = sample_rate
1093
+ self._buffer = bytearray()
1094
+ self._lock = threading.Lock()
1095
+ self._stream = None
1096
+ self._drained = threading.Event()
1097
+ self._drained.set()
1098
+
1099
+ def _callback(self, outdata, frames, _time_info, _status) -> None:
1100
+ need = frames * 2
1101
+ with self._lock:
1102
+ chunk = bytes(self._buffer[:need])
1103
+ del self._buffer[:need]
1104
+ empty = not self._buffer
1105
+ if len(chunk) < need:
1106
+ chunk += b"\x00" * (need - len(chunk))
1107
+ if empty:
1108
+ self._drained.set()
1109
+ outdata[:] = np.frombuffer(chunk, dtype=np.int16).reshape(-1, 1)
1110
+
1111
+ def _ensure_stream(self) -> None:
1112
+ if self._stream is not None:
1113
+ return
1114
+ self._stream = sd.OutputStream(
1115
+ samplerate=self._rate,
1116
+ channels=1,
1117
+ dtype="int16",
1118
+ device=self._device,
1119
+ callback=self._callback,
1120
+ )
1121
+ self._stream.start()
1122
+
1123
+ def feed(self, data: bytes) -> bool:
1124
+ if not data:
1125
+ return
1126
+ self._ensure_stream()
1127
+ self._drained.clear()
1128
+ with self._lock:
1129
+ self._buffer.extend(data)
1130
+
1131
+ def stop(self) -> None:
1132
+ with self._lock:
1133
+ self._buffer.clear()
1134
+ self._close()
1135
+
1136
+ def close(self, timeout: float = 30.0) -> int:
1137
+ """Wait for the buffer to drain, then release the device."""
1138
+ deadline = time.monotonic() + timeout
1139
+ while not self._drained.is_set() and time.monotonic() < deadline:
1140
+ time.sleep(0.02)
1141
+ if self._drained.is_set():
1142
+ time.sleep(0.12)
1143
+ remaining = len(self._buffer)
1144
+ self._close()
1145
+ return remaining
1146
+
1147
+ def _close(self) -> None:
1148
+ stream, self._stream = self._stream, None
1149
+ if stream is not None:
1150
+ try:
1151
+ stream.stop()
1152
+ stream.close()
1153
+ except Exception:
1154
+ pass
1155
+ self._drained.set()
1156
+
1157
+
1087
1158
  def _play_pcm16(pcm_bytes: bytes, sample_rate: int = 24000, device: int | None = None) -> None:
1088
1159
  if not pcm_bytes:
1089
1160
  return
@@ -1106,9 +1177,22 @@ def _chat_trace(etype: str, event: dict, state: dict) -> None:
1106
1177
  console.print(f"[dim] [{etype}{extra}][/dim]", markup=False)
1107
1178
 
1108
1179
 
1109
- async def _chat_handle_delta(etype: str, event: dict, state: dict, verbose: bool, playing: asyncio.Event) -> None:
1180
+ async def _chat_handle_delta(
1181
+ etype: str,
1182
+ event: dict,
1183
+ state: dict,
1184
+ verbose: bool,
1185
+ playing: asyncio.Event,
1186
+ player: _StreamingPlayback | None = None,
1187
+ ) -> None:
1110
1188
  if etype == "conversation.item.input_audio_transcription.delta":
1111
- state["transcript"].append(event.get("delta", ""))
1189
+ if event.get("partial"):
1190
+ state["transcript"] = [event.get("partial_transcript") or event.get("delta", "")]
1191
+ else:
1192
+ state["transcript"].append(event.get("delta", ""))
1193
+ if verbose:
1194
+ sys.stdout.write("\r[you: " + "".join(state["transcript"]).strip()[-70:] + "]")
1195
+ sys.stdout.flush()
1112
1196
  elif etype == "response.output_audio_transcript.delta":
1113
1197
  delta = event.get("delta", "")
1114
1198
  state["text"].append(delta)
@@ -1117,12 +1201,16 @@ async def _chat_handle_delta(etype: str, event: dict, state: dict, verbose: bool
1117
1201
  elif etype == "response.output_audio.delta":
1118
1202
  playing.set()
1119
1203
  try:
1120
- state["audio"].append(base64.b64decode(event.get("delta", "")))
1204
+ pcm = base64.b64decode(event.get("delta", ""))
1121
1205
  except Exception:
1122
- pass
1206
+ return
1207
+ if player is not None:
1208
+ player.feed(pcm)
1209
+ else:
1210
+ state["audio"].append(pcm)
1123
1211
 
1124
1212
 
1125
- async def _chat_handle_done(
1213
+ async def _chat_handle_done( # noqa: C901
1126
1214
  etype: str,
1127
1215
  event: dict,
1128
1216
  state: dict,
@@ -1130,9 +1218,11 @@ async def _chat_handle_done(
1130
1218
  loop: asyncio.AbstractEventLoop,
1131
1219
  output_device_idx: int | None,
1132
1220
  playing: asyncio.Event,
1133
- ) -> None:
1221
+ ) -> None: # noqa: C901
1134
1222
  if etype == "conversation.item.input_audio_transcription.completed":
1135
- transcript = event.get("transcript", "").strip() or " ".join(state["transcript"]).strip()
1223
+ transcript = event.get("transcript", "").strip() or "".join(state["transcript"]).strip()
1224
+ if state["transcript"]:
1225
+ sys.stdout.write("\r" + " " * 80 + "\r")
1136
1226
  state["transcript"] = []
1137
1227
  sys.stdout.write("\r" + " " * 60 + "\r")
1138
1228
  if transcript:
@@ -1141,16 +1231,30 @@ async def _chat_handle_done(
1141
1231
  if state["text"]:
1142
1232
  sys.stdout.write("\n")
1143
1233
  sys.stdout.flush()
1144
- if state["audio"]:
1234
+ player: _StreamingPlayback | None = state.get("player")
1235
+ if player is not None:
1236
+ await loop.run_in_executor(None, player.close)
1237
+ state["player"] = None
1238
+ elif state["audio"]:
1145
1239
  pcm = b"".join(state["audio"])
1146
1240
  await loop.run_in_executor(None, _play_pcm16, pcm, 24000, output_device_idx)
1147
1241
  state["audio"] = []
1148
1242
  state["text"] = []
1149
1243
  await asyncio.sleep(_PLAYBACK_COOLDOWN)
1150
1244
  playing.clear()
1245
+ elif etype == "response.cancelled":
1246
+ state["text"] = []
1247
+ state["audio"] = []
1248
+ player = state.get("player")
1249
+ if player is not None:
1250
+ player.stop()
1251
+ state["player"] = None
1252
+ playing.clear()
1253
+ elif etype == "response.metrics" and verbose:
1254
+ console.print(f"[dim] metrics {event.get('metrics')}[/dim]")
1151
1255
 
1152
1256
 
1153
- async def _chat_receiver(ws, output_device_idx: int | None, verbose: bool, loop: asyncio.AbstractEventLoop, stop_event: asyncio.Event, playing: asyncio.Event) -> None:
1257
+ async def _chat_receiver(ws, output_device_idx: int | None, verbose: bool, loop: asyncio.AbstractEventLoop, stop_event: asyncio.Event, playing: asyncio.Event) -> None: # noqa: C901
1154
1258
  state: dict = {"audio": [], "text": [], "transcript": []}
1155
1259
 
1156
1260
  async for msg in ws:
@@ -1162,11 +1266,22 @@ async def _chat_receiver(ws, output_device_idx: int | None, verbose: bool, loop:
1162
1266
  if verbose:
1163
1267
  _chat_trace(etype, event, state)
1164
1268
 
1165
- if "delta" in etype:
1166
- await _chat_handle_delta(etype, event, state, verbose, playing)
1269
+ if etype == "response.output_audio.delta":
1270
+ if state.get("player") is None:
1271
+ state["player"] = _StreamingPlayback(output_device_idx)
1272
+ if etype in ("response.cancelled", "response.metrics"):
1273
+ # Neither name contains "done"/"completed", so route them explicitly.
1274
+ await _chat_handle_done(etype, event, state, verbose, loop, output_device_idx, playing)
1275
+ elif "delta" in etype:
1276
+ await _chat_handle_delta(etype, event, state, verbose, playing, state.get("player"))
1167
1277
  elif "done" in etype or "completed" in etype:
1168
1278
  await _chat_handle_done(etype, event, state, verbose, loop, output_device_idx, playing)
1169
1279
  elif etype == "input_audio_buffer.speech_started":
1280
+ player = state.get("player")
1281
+ if player is not None:
1282
+ player.stop()
1283
+ state["player"] = None
1284
+ playing.clear()
1170
1285
  sys.stdout.write("\r[detecting speech...] \r")
1171
1286
  sys.stdout.flush()
1172
1287
  elif etype == "response.done":