primocode 11.2.0 → 11.3.1

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.
@@ -200,6 +200,43 @@ def main() -> int:
200
200
  return 1
201
201
  print(json.dumps({"ok": True, "palavras": ws}, ensure_ascii=False))
202
202
  return 0
203
+ if acao == "servir":
204
+ # `... servir [idioma]`: processo vivo do app (modo voz ao vivo). O modelo carrega UMA vez; cada linha de entrada é
205
+ # {"id":N,"arquivo":"x.wav"} e cada linha de saída é {"id":N,"ok":true,"texto":"..."}. Primeira linha: {"pronto":true}.
206
+ if not disponivel():
207
+ print(json.dumps({"ok": False, "error": "o faster-whisper não está instalado"}), flush=True)
208
+ return 1
209
+ idioma = sys.argv[2] if len(sys.argv) > 2 else "pt"
210
+ try:
211
+ carregar()
212
+ except Exception as e:
213
+ print(json.dumps({"ok": False, "error": str(e)}), flush=True)
214
+ return 1
215
+ print(json.dumps({"pronto": True, "modelo": MODELO}), flush=True)
216
+ for linha in sys.stdin:
217
+ linha = linha.strip()
218
+ if not linha:
219
+ continue
220
+ pedido = {}
221
+ try:
222
+ pedido = json.loads(linha)
223
+ texto = transcrever(Path(pedido["arquivo"]), idioma)
224
+ print(json.dumps({"id": pedido.get("id"), "ok": True, "texto": texto}, ensure_ascii=False), flush=True)
225
+ except Exception as e:
226
+ print(json.dumps({"id": pedido.get("id"), "ok": False, "error": str(e)}), flush=True)
227
+ return 0
228
+ if acao == "arquivo":
229
+ # `... arquivo <wav> [idioma]`: a fala de um arquivo vira texto (o app desktop grava no microfone e manda para cá).
230
+ if not disponivel():
231
+ print(json.dumps({"ok": False, "error": "o faster-whisper não está instalado"}))
232
+ return 1
233
+ try:
234
+ texto = transcrever(Path(sys.argv[2]), sys.argv[3] if len(sys.argv) > 3 else "pt")
235
+ except Exception as e:
236
+ print(json.dumps({"ok": False, "error": str(e)}))
237
+ return 1
238
+ print(json.dumps({"ok": True, "texto": texto}, ensure_ascii=False))
239
+ return 0
203
240
  if acao != "baixar":
204
241
  print(json.dumps({"ok": False, "error": f"ação desconhecida: {acao}"}))
205
242
  return 2