livekit-plugins-speechmatics 0.0.2__py3-none-any.whl → 1.0.0.dev4__py3-none-any.whl
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.
- livekit/plugins/speechmatics/stt.py +13 -23
- livekit/plugins/speechmatics/types.py +5 -7
- livekit/plugins/speechmatics/utils.py +3 -9
- livekit/plugins/speechmatics/version.py +1 -1
- {livekit_plugins_speechmatics-0.0.2.dist-info → livekit_plugins_speechmatics-1.0.0.dev4.dist-info}/METADATA +10 -20
- livekit_plugins_speechmatics-1.0.0.dev4.dist-info/RECORD +10 -0
- {livekit_plugins_speechmatics-0.0.2.dist-info → livekit_plugins_speechmatics-1.0.0.dev4.dist-info}/WHEEL +1 -2
- livekit_plugins_speechmatics-0.0.2.dist-info/RECORD +0 -11
- livekit_plugins_speechmatics-0.0.2.dist-info/top_level.txt +0 -1
@@ -20,9 +20,9 @@ import dataclasses
|
|
20
20
|
import json
|
21
21
|
import os
|
22
22
|
import weakref
|
23
|
-
from typing import Dict, List, Optional
|
24
23
|
|
25
24
|
import aiohttp
|
25
|
+
|
26
26
|
from livekit.agents import (
|
27
27
|
DEFAULT_API_CONNECT_OPTIONS,
|
28
28
|
APIConnectOptions,
|
@@ -57,8 +57,8 @@ class STT(stt.STT):
|
|
57
57
|
url="wss://eu2.rt.speechmatics.com/v2",
|
58
58
|
),
|
59
59
|
audio_settings: AudioSettings = AudioSettings(),
|
60
|
-
http_session:
|
61
|
-
extra_headers:
|
60
|
+
http_session: aiohttp.ClientSession | None = None,
|
61
|
+
extra_headers: dict | None = None,
|
62
62
|
):
|
63
63
|
super().__init__(
|
64
64
|
capabilities=stt.STTCapabilities(
|
@@ -91,9 +91,9 @@ class STT(stt.STT):
|
|
91
91
|
def stream(
|
92
92
|
self,
|
93
93
|
*,
|
94
|
-
language:
|
94
|
+
language: str | None = None,
|
95
95
|
conn_options: APIConnectOptions = DEFAULT_API_CONNECT_OPTIONS,
|
96
|
-
) ->
|
96
|
+
) -> SpeechStream:
|
97
97
|
config = dataclasses.replace(self._audio_settings)
|
98
98
|
stream = SpeechStream(
|
99
99
|
stt=self,
|
@@ -118,11 +118,9 @@ class SpeechStream(stt.SpeechStream):
|
|
118
118
|
connection_settings: ConnectionSettings,
|
119
119
|
conn_options: APIConnectOptions,
|
120
120
|
http_session: aiohttp.ClientSession,
|
121
|
-
extra_headers:
|
121
|
+
extra_headers: dict | None = None,
|
122
122
|
) -> None:
|
123
|
-
super().__init__(
|
124
|
-
stt=stt, conn_options=conn_options, sample_rate=audio_settings.sample_rate
|
125
|
-
)
|
123
|
+
super().__init__(stt=stt, conn_options=conn_options, sample_rate=audio_settings.sample_rate)
|
126
124
|
self._transcription_config = transcription_config
|
127
125
|
self._audio_settings = audio_settings
|
128
126
|
self._connection_settings = connection_settings
|
@@ -188,9 +186,7 @@ class SpeechStream(stt.SpeechStream):
|
|
188
186
|
return
|
189
187
|
|
190
188
|
# this will trigger a reconnection, see the _run loop
|
191
|
-
raise APIStatusError(
|
192
|
-
message="Speechmatics connection closed unexpectedly"
|
193
|
-
)
|
189
|
+
raise APIStatusError(message="Speechmatics connection closed unexpectedly")
|
194
190
|
|
195
191
|
try:
|
196
192
|
data = json.loads(msg.data)
|
@@ -229,9 +225,7 @@ class SpeechStream(stt.SpeechStream):
|
|
229
225
|
await ws.close()
|
230
226
|
|
231
227
|
async def _connect_ws(self) -> aiohttp.ClientWebSocketResponse:
|
232
|
-
api_key = self._connection_settings.api_key or os.environ.get(
|
233
|
-
"SPEECHMATICS_API_KEY"
|
234
|
-
)
|
228
|
+
api_key = self._connection_settings.api_key or os.environ.get("SPEECHMATICS_API_KEY")
|
235
229
|
if api_key is None:
|
236
230
|
raise ValueError(
|
237
231
|
"Speechmatics API key is required. "
|
@@ -244,9 +238,7 @@ class SpeechStream(stt.SpeechStream):
|
|
244
238
|
"Authorization": f"Bearer {api_key}",
|
245
239
|
**self._extra_headers,
|
246
240
|
}
|
247
|
-
url = sanitize_url(
|
248
|
-
self._connection_settings.url, self._transcription_config.language
|
249
|
-
)
|
241
|
+
url = sanitize_url(self._connection_settings.url, self._transcription_config.language)
|
250
242
|
return await self._session.ws_connect(
|
251
243
|
url,
|
252
244
|
ssl=self._connection_settings.ssl_context,
|
@@ -281,9 +273,7 @@ class SpeechStream(stt.SpeechStream):
|
|
281
273
|
usage_event = stt.SpeechEvent(
|
282
274
|
type=stt.SpeechEventType.RECOGNITION_USAGE,
|
283
275
|
alternatives=[],
|
284
|
-
recognition_usage=stt.RecognitionUsage(
|
285
|
-
audio_duration=self._speech_duration
|
286
|
-
),
|
276
|
+
recognition_usage=stt.RecognitionUsage(audio_duration=self._speech_duration),
|
287
277
|
)
|
288
278
|
self._event_ch.send_nowait(usage_event)
|
289
279
|
self._speech_duration = 0
|
@@ -295,8 +285,8 @@ class SpeechStream(stt.SpeechStream):
|
|
295
285
|
raise Exception("Speechmatics connection closed unexpectedly")
|
296
286
|
|
297
287
|
|
298
|
-
def live_transcription_to_speech_data(data: dict) ->
|
299
|
-
speech_data:
|
288
|
+
def live_transcription_to_speech_data(data: dict) -> list[stt.SpeechData]:
|
289
|
+
speech_data: list[stt.SpeechData] = []
|
300
290
|
|
301
291
|
for result in data.get("results", []):
|
302
292
|
start_time, end_time, is_eos = (
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import ssl
|
2
2
|
from dataclasses import asdict, dataclass, field
|
3
3
|
from enum import Enum
|
4
|
-
from typing import Any,
|
4
|
+
from typing import Any, Optional
|
5
5
|
|
6
6
|
|
7
7
|
@dataclass
|
@@ -20,10 +20,10 @@ class TranscriptionConfig:
|
|
20
20
|
diarization: Optional[str] = None
|
21
21
|
"""Indicates type of diarization to use, if any."""
|
22
22
|
|
23
|
-
additional_vocab: Optional[
|
23
|
+
additional_vocab: Optional[dict] = None
|
24
24
|
"""Additional vocabulary that is not part of the standard language."""
|
25
25
|
|
26
|
-
punctuation_overrides: Optional[
|
26
|
+
punctuation_overrides: Optional[dict] = None
|
27
27
|
"""Permitted puctuation marks for advanced punctuation."""
|
28
28
|
|
29
29
|
enable_entities: Optional[bool] = None
|
@@ -46,11 +46,9 @@ class TranscriptionConfig:
|
|
46
46
|
"""Indicates if partials for transcription, where words are produced
|
47
47
|
immediately, is enabled."""
|
48
48
|
|
49
|
-
def asdict(self) ->
|
49
|
+
def asdict(self) -> dict[Any, Any]:
|
50
50
|
"""Returns model as a dict while excluding None values recursively."""
|
51
|
-
return asdict(
|
52
|
-
self, dict_factory=lambda x: {k: v for (k, v) in x if v is not None}
|
53
|
-
)
|
51
|
+
return asdict(self, dict_factory=lambda x: {k: v for (k, v) in x if v is not None})
|
54
52
|
|
55
53
|
|
56
54
|
@dataclass
|
@@ -5,26 +5,20 @@ import aiohttp
|
|
5
5
|
|
6
6
|
|
7
7
|
async def get_access_token(api_key: str) -> str:
|
8
|
-
mp_api_url = os.getenv(
|
9
|
-
"SPEECHMATICS_MANAGEMENT_PLATFORM_URL", "https://mp.speechmatics.com"
|
10
|
-
)
|
8
|
+
mp_api_url = os.getenv("SPEECHMATICS_MANAGEMENT_PLATFORM_URL", "https://mp.speechmatics.com")
|
11
9
|
endpoint = f"{mp_api_url}/v1/api_keys"
|
12
10
|
params = {"type": "rt", "sm-sdk": get_sdk_version()}
|
13
11
|
json_body = {"ttl": 60}
|
14
12
|
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
|
15
13
|
|
16
14
|
async with aiohttp.ClientSession() as session:
|
17
|
-
async with session.post(
|
18
|
-
endpoint, params=params, json=json_body, headers=headers
|
19
|
-
) as resp:
|
15
|
+
async with session.post(endpoint, params=params, json=json_body, headers=headers) as resp:
|
20
16
|
if resp.status == 201:
|
21
17
|
try:
|
22
18
|
data = await resp.json()
|
23
19
|
return data["key_value"]
|
24
20
|
except (ValueError, KeyError) as e:
|
25
|
-
raise Exception(
|
26
|
-
f"Failed to parse Speechmatics access token response: {e}"
|
27
|
-
)
|
21
|
+
raise Exception(f"Failed to parse Speechmatics access token response: {e}")
|
28
22
|
else:
|
29
23
|
error_message = await resp.text()
|
30
24
|
raise Exception(
|
@@ -1,35 +1,25 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: livekit-plugins-speechmatics
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 1.0.0.dev4
|
4
4
|
Summary: Agent Framework plugin for Speechmatics
|
5
|
-
Home-page: https://github.com/livekit/agents
|
6
|
-
License: Apache-2.0
|
7
5
|
Project-URL: Documentation, https://docs.livekit.io
|
8
6
|
Project-URL: Website, https://livekit.io/
|
9
7
|
Project-URL: Source, https://github.com/livekit/agents
|
10
|
-
|
8
|
+
Author-email: LiveKit <support@livekit.io>
|
9
|
+
License-Expression: Apache-2.0
|
10
|
+
Keywords: audio,livekit,realtime,video,webrtc
|
11
11
|
Classifier: Intended Audience :: Developers
|
12
12
|
Classifier: License :: OSI Approved :: Apache Software License
|
13
|
-
Classifier: Topic :: Multimedia :: Sound/Audio
|
14
|
-
Classifier: Topic :: Multimedia :: Video
|
15
|
-
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
16
13
|
Classifier: Programming Language :: Python :: 3
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
17
15
|
Classifier: Programming Language :: Python :: 3.9
|
18
16
|
Classifier: Programming Language :: Python :: 3.10
|
19
|
-
Classifier:
|
17
|
+
Classifier: Topic :: Multimedia :: Sound/Audio
|
18
|
+
Classifier: Topic :: Multimedia :: Video
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
20
20
|
Requires-Python: >=3.9.0
|
21
|
+
Requires-Dist: livekit-agents>=1.0.0.dev4
|
21
22
|
Description-Content-Type: text/markdown
|
22
|
-
Requires-Dist: livekit-agents<1.0.0,>=0.12.16
|
23
|
-
Dynamic: classifier
|
24
|
-
Dynamic: description
|
25
|
-
Dynamic: description-content-type
|
26
|
-
Dynamic: home-page
|
27
|
-
Dynamic: keywords
|
28
|
-
Dynamic: license
|
29
|
-
Dynamic: project-url
|
30
|
-
Dynamic: requires-dist
|
31
|
-
Dynamic: requires-python
|
32
|
-
Dynamic: summary
|
33
23
|
|
34
24
|
# LiveKit Plugins Speechmatics
|
35
25
|
|
@@ -0,0 +1,10 @@
|
|
1
|
+
livekit/plugins/speechmatics/__init__.py,sha256=u1BkFot3ggFvlbdohgrWSvPgcfqO79dsRLN6lJsyxnU,919
|
2
|
+
livekit/plugins/speechmatics/log.py,sha256=O1iyAF7cHUu_iMXh6l7KRwwWeDB5QyABI_qzAb0cs04,75
|
3
|
+
livekit/plugins/speechmatics/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
+
livekit/plugins/speechmatics/stt.py,sha256=e2SS_y8QkTLyxJ1ct05jO5rYzUhDTnLwgCpZumbDOHQ,11131
|
5
|
+
livekit/plugins/speechmatics/types.py,sha256=F4Ky9ajT7OztXqspXUCqRX1pwOLMOgWnbdLyJLMi2oQ,4609
|
6
|
+
livekit/plugins/speechmatics/utils.py,sha256=GGt3Nc3tf38j-xhUCgmbh_mpT4nIB3kcBWsI6pMgA5A,1811
|
7
|
+
livekit/plugins/speechmatics/version.py,sha256=Ztk_WrQGamSjN36CY9ni_L5SabyZMyhBNQuwumCoIMI,605
|
8
|
+
livekit_plugins_speechmatics-1.0.0.dev4.dist-info/METADATA,sha256=PIcZd1K7xEE7n7BXie6a7XFLs_5N8pkcGGXp39Tr5Rk,1985
|
9
|
+
livekit_plugins_speechmatics-1.0.0.dev4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
10
|
+
livekit_plugins_speechmatics-1.0.0.dev4.dist-info/RECORD,,
|
@@ -1,11 +0,0 @@
|
|
1
|
-
livekit/plugins/speechmatics/__init__.py,sha256=u1BkFot3ggFvlbdohgrWSvPgcfqO79dsRLN6lJsyxnU,919
|
2
|
-
livekit/plugins/speechmatics/log.py,sha256=O1iyAF7cHUu_iMXh6l7KRwwWeDB5QyABI_qzAb0cs04,75
|
3
|
-
livekit/plugins/speechmatics/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
-
livekit/plugins/speechmatics/stt.py,sha256=R79Bh0rC04mnyYqfEr8nDv-A-LboH3Ol-c2f9wbqS-Q,11342
|
5
|
-
livekit/plugins/speechmatics/types.py,sha256=pqcFr9jzyuoENUGsF_Bagh7mzYSMMB2Q69xYnD5pLYo,4637
|
6
|
-
livekit/plugins/speechmatics/utils.py,sha256=0w8CV1rtQnfR5hTzeKhIpFBO5jluv-zq89UT3t8dgr8,1893
|
7
|
-
livekit/plugins/speechmatics/version.py,sha256=eDKVGIi8wd5-S0J4-EIahcMFFXzqOGXghEfr_1sXpAc,600
|
8
|
-
livekit_plugins_speechmatics-0.0.2.dist-info/METADATA,sha256=hoF3L17vOrULmaRz_FzMKN916G9G-u5UCoUsrCSxbBY,2190
|
9
|
-
livekit_plugins_speechmatics-0.0.2.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
|
10
|
-
livekit_plugins_speechmatics-0.0.2.dist-info/top_level.txt,sha256=OoDok3xUmXbZRvOrfvvXB-Juu4DX79dlq188E19YHoo,8
|
11
|
-
livekit_plugins_speechmatics-0.0.2.dist-info/RECORD,,
|
@@ -1 +0,0 @@
|
|
1
|
-
livekit
|