appsocom 0.8.0__tar.gz → 0.9.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.
- {appsocom-0.8.0 → appsocom-0.9.0}/PKG-INFO +1 -1
- {appsocom-0.8.0 → appsocom-0.9.0}/appsocom/__init__.py +71 -1
- {appsocom-0.8.0 → appsocom-0.9.0}/appsocom.egg-info/PKG-INFO +1 -1
- {appsocom-0.8.0 → appsocom-0.9.0}/pyproject.toml +1 -1
- {appsocom-0.8.0 → appsocom-0.9.0}/tests/test_sfukit.py +32 -0
- {appsocom-0.8.0 → appsocom-0.9.0}/LICENSE +0 -0
- {appsocom-0.8.0 → appsocom-0.9.0}/README.md +0 -0
- {appsocom-0.8.0 → appsocom-0.9.0}/appsocom.egg-info/SOURCES.txt +0 -0
- {appsocom-0.8.0 → appsocom-0.9.0}/appsocom.egg-info/dependency_links.txt +0 -0
- {appsocom-0.8.0 → appsocom-0.9.0}/appsocom.egg-info/top_level.txt +0 -0
- {appsocom-0.8.0 → appsocom-0.9.0}/setup.cfg +0 -0
|
@@ -31,7 +31,7 @@ __all__ = [
|
|
|
31
31
|
"assistant_tools",
|
|
32
32
|
"verify_assistant_tool_call",
|
|
33
33
|
]
|
|
34
|
-
__version__ = "0.
|
|
34
|
+
__version__ = "0.9.0"
|
|
35
35
|
|
|
36
36
|
SIGNATURE_HEADER = "X-SfuKit-Signature"
|
|
37
37
|
_ID = re.compile(r"^[A-Za-z0-9._:@-]{1,128}$")
|
|
@@ -675,6 +675,76 @@ class SfuKit:
|
|
|
675
675
|
"""The project's own daily speech cap in US dollars (None = the server's default)."""
|
|
676
676
|
return self.request("PUT", "/speech/config", {"dailyBudgetUsd": daily_budget_usd})
|
|
677
677
|
|
|
678
|
+
# ---------- Translation (/languages, /translate/*) and AI interpreters ----------
|
|
679
|
+
|
|
680
|
+
def get_languages(self) -> List[Dict[str, Any]]:
|
|
681
|
+
"""The languages every AI service takes: [{"code", "name", "native", "quality", "text",
|
|
682
|
+
"speechToText", "textToSpeech", "rtl"?}]. Public; good for a language picker."""
|
|
683
|
+
return self.request("GET", "/languages")["languages"]
|
|
684
|
+
|
|
685
|
+
def translate_text(
|
|
686
|
+
self,
|
|
687
|
+
text: str,
|
|
688
|
+
to: Union[str, List[str]],
|
|
689
|
+
from_: Optional[str] = None,
|
|
690
|
+
**options: Any,
|
|
691
|
+
) -> Dict[str, Any]:
|
|
692
|
+
"""Translate up to 20,000 characters into one language or up to 20 ("fr" or ["fr", "de"]).
|
|
693
|
+
|
|
694
|
+
from_: the source language (unset = detected). options: tier ("standard", "smart", "best"),
|
|
695
|
+
context (what the text is, for tone), formality ("formal" or "informal"), glossary
|
|
696
|
+
({"term": "translation"}), user and label (for the AI Tasks audit and per-person allowance).
|
|
697
|
+
Returns {"from", "to", "translations": {code: text}, "text"? (one target), "tier", "usage"}.
|
|
698
|
+
Billed as AI Tasks credits, within the project's AI Tasks daily cap.
|
|
699
|
+
"""
|
|
700
|
+
return self.request("POST", "/translate/text", _body({"text": text, "to": to, "from": from_, **options}))
|
|
701
|
+
|
|
702
|
+
def translate_speech(
|
|
703
|
+
self,
|
|
704
|
+
audio: Union[bytes, bytearray, memoryview],
|
|
705
|
+
to: Union[str, List[str]],
|
|
706
|
+
content_type: str = "application/octet-stream",
|
|
707
|
+
from_: Optional[str] = None,
|
|
708
|
+
speak: bool = False,
|
|
709
|
+
timeout: float = 180.0,
|
|
710
|
+
**options: Any,
|
|
711
|
+
) -> Dict[str, Any]:
|
|
712
|
+
"""Hear a recording (up to 25 MB), translate it, and with speak=True voice it (up to 5 languages).
|
|
713
|
+
|
|
714
|
+
options: voice, format ("mp3" or "wav"), tier, context, formality, user, label.
|
|
715
|
+
Returns {"from", "transcript", "seconds", "to", "translations", "text"?, "audio"? ({code: {"url",
|
|
716
|
+
"expiresAt"}}), "usage"}. Errors carry "step": "speech to text", "translate" or "text to speech".
|
|
717
|
+
"""
|
|
718
|
+
if not isinstance(audio, (bytes, bytearray, memoryview)):
|
|
719
|
+
raise SfuKitError(400, "audio must be bytes")
|
|
720
|
+
q: Dict[str, Any] = {"to": ",".join(to) if isinstance(to, (list, tuple)) else to}
|
|
721
|
+
if from_:
|
|
722
|
+
q["from"] = from_
|
|
723
|
+
if speak:
|
|
724
|
+
q["speak"] = "true"
|
|
725
|
+
q.update({k: v for k, v in options.items() if v is not None})
|
|
726
|
+
return self.request("POST", f"/translate/speech?{urllib.parse.urlencode(q)}", _encoded=(bytes(audio), content_type), timeout=timeout)
|
|
727
|
+
|
|
728
|
+
def start_interpreter(self, room_id: str, language: str, from_: Optional[str] = None, **options: Any) -> Dict[str, Any]:
|
|
729
|
+
"""Add an AI interpreter to a room: it speaks what people say in `language` ("fr", "de", …).
|
|
730
|
+
Only people who chose that language (room.setInterpretation in the client, or the kits'
|
|
731
|
+
My language menu) hear it. Up to 3 per room, one per language.
|
|
732
|
+
|
|
733
|
+
options: name, voice_name, tts ("cartesia" or "elevenlabs"), metadata. Returns {"roomId",
|
|
734
|
+
"agentId", "participant"}. Billed as AI Agent minutes plus Speech characters, within the
|
|
735
|
+
project's Speech daily cap.
|
|
736
|
+
"""
|
|
737
|
+
body = _body({"language": language, "from": from_, **options}, {"voice_name": "voiceName"})
|
|
738
|
+
return self.request("POST", f"/rooms/{_id(room_id)}/interpreters", body)
|
|
739
|
+
|
|
740
|
+
def list_interpreters(self, room_id: str) -> List[Dict[str, Any]]:
|
|
741
|
+
"""The room's AI interpreters: [{"agentId", "language", "listeners"}]."""
|
|
742
|
+
return self.request("GET", f"/rooms/{_id(room_id)}/interpreters")["interpreters"]
|
|
743
|
+
|
|
744
|
+
def stop_interpreter(self, room_id: str, agent_id: str) -> None:
|
|
745
|
+
"""Remove an AI interpreter from a room."""
|
|
746
|
+
self.request("DELETE", f"/rooms/{_id(room_id)}/interpreters/{_id(agent_id)}")
|
|
747
|
+
|
|
678
748
|
# ---------- Videos (video on demand on R2) ----------
|
|
679
749
|
|
|
680
750
|
#: Seconds a video upload may take (a whole file, or one part of it); longer than `timeout`.
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "appsocom"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.9.0"
|
|
8
8
|
description = "Python server SDK for Appsocom Live video calls: join tokens, rooms, moderation and webhook verification"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -346,6 +346,16 @@ class ServicesHandler(BaseHTTPRequestHandler):
|
|
|
346
346
|
if raw == b"quota":
|
|
347
347
|
return self._reply(429, {"error": "the project's daily speech budget is used up"})
|
|
348
348
|
return self._reply(200, {"text": "hello", "seconds": 3, "provider": "deepgram"})
|
|
349
|
+
if path == "/languages":
|
|
350
|
+
return self._reply(200, {"languages": [{"code": "fr", "name": "French"}]})
|
|
351
|
+
if path == "/translate/text":
|
|
352
|
+
return self._reply(200, {"from": "en", "to": ["fr"], "translations": {"fr": "Bonjour"}, "text": "Bonjour"})
|
|
353
|
+
if path == "/translate/speech":
|
|
354
|
+
return self._reply(200, {"from": "en", "transcript": "hello", "translations": {"fr": "bonjour"}})
|
|
355
|
+
if path.endswith("/interpreters") and self.command == "GET":
|
|
356
|
+
return self._reply(200, {"interpreters": [{"agentId": "a1", "language": "fr", "listeners": 2}], "max": 3})
|
|
357
|
+
if "/interpreters" in path:
|
|
358
|
+
return self._reply(200, {"roomId": "r1", "agentId": "a1"} if self.command == "POST" else {"stopped": True})
|
|
349
359
|
if path == "/speech/config":
|
|
350
360
|
return self._reply(200, {"dailyBudgetUsd": body.get("dailyBudgetUsd"), "effectiveDailyCapUsd": 5})
|
|
351
361
|
if path == "/videos/uploads":
|
|
@@ -451,6 +461,28 @@ class ServicesTests(unittest.TestCase):
|
|
|
451
461
|
self.assertEqual(self.last()[:2] + (self.last()[3],), ("PUT", "/speech/config", {"dailyBudgetUsd": None}))
|
|
452
462
|
self.assertEqual(self.kit.set_speech_daily_budget(2)["dailyBudgetUsd"], 2)
|
|
453
463
|
|
|
464
|
+
def test_translation_and_interpreters(self):
|
|
465
|
+
self.assertEqual(self.kit.get_languages()[0]["code"], "fr")
|
|
466
|
+
self.assertEqual(self.last()[:2], ("GET", "/languages"))
|
|
467
|
+
out = self.kit.translate_text("Hello", ["fr", "de"], from_="en", tier="smart", glossary={"Appsocom": "Appsocom"})
|
|
468
|
+
self.assertEqual(out["text"], "Bonjour")
|
|
469
|
+
self.assertEqual(self.last()[:2] + (self.last()[3],), ("POST", "/translate/text", {"text": "Hello", "to": ["fr", "de"], "from": "en", "tier": "smart", "glossary": {"Appsocom": "Appsocom"}}))
|
|
470
|
+
self.kit.translate_text("Hi", "fr")
|
|
471
|
+
self.assertEqual(self.last()[3], {"text": "Hi", "to": "fr"})
|
|
472
|
+
heard = self.kit.translate_speech(b"\x00\x01", ["fr", "de"], content_type="audio/webm", speak=True, voice="v1")
|
|
473
|
+
self.assertEqual(heard["transcript"], "hello")
|
|
474
|
+
method, path, headers, _ = self.last()
|
|
475
|
+
self.assertEqual((method, path, headers["content-type"]), ("POST", "/translate/speech?to=fr%2Cde&speak=true&voice=v1", "audio/webm"))
|
|
476
|
+
self.assertEqual(ServicesHandler.seen[-1][3], b"\x00\x01")
|
|
477
|
+
with self.assertRaises(SfuKitError):
|
|
478
|
+
self.kit.translate_speech("not bytes", "fr") # type: ignore[arg-type]
|
|
479
|
+
self.assertEqual(self.kit.start_interpreter("room-1", "fr", voice_name="v2")["agentId"], "a1")
|
|
480
|
+
self.assertEqual(self.last()[:2] + (self.last()[3],), ("POST", "/rooms/room-1/interpreters", {"language": "fr", "voiceName": "v2"}))
|
|
481
|
+
self.assertEqual(self.kit.list_interpreters("r1")[0]["listeners"], 2)
|
|
482
|
+
self.assertEqual(self.last()[:2], ("GET", "/rooms/r1/interpreters"))
|
|
483
|
+
self.assertIsNone(self.kit.stop_interpreter("r1", "a1"))
|
|
484
|
+
self.assertEqual(self.last()[:2], ("DELETE", "/rooms/r1/interpreters/a1"))
|
|
485
|
+
|
|
454
486
|
def test_the_video_methods_call_the_right_routes(self):
|
|
455
487
|
kit, v = self.kit, "a" * 32
|
|
456
488
|
calls = []
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|