Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/smallestai/cli/lib/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def make_client(auth_client: AuthClient):

base = base.rstrip("/")
ws = base.replace("https://", "wss://").replace("http://", "ws://")
env = SmallestAIEnvironment(atoms=f"{base}/atoms/v1", waves=base, waves_ws=ws)
env = SmallestAIEnvironment(
atoms=f"{base}/atoms/v1", waves=base, waves_ws=ws, payment=base
)
return SmallestAI(api_key=key, environment=env)
return SmallestAI(api_key=key)
16 changes: 11 additions & 5 deletions src/smallestai/waves/stream_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,11 @@ def synthesize(self, text: str) -> Generator[bytes, None, None]:
"""Synthesize a single text string and stream back PCM audio chunks."""
self._reset_state()
self._connect()
ws = self.ws
assert ws is not None # _connect() raises unless the socket opened

payload = self._create_payload(text)
self.ws.send(json.dumps(payload))
ws.send(json.dumps(payload))

while True:
if not self.error_queue.empty():
Expand All @@ -187,7 +189,7 @@ def synthesize(self, text: str) -> Generator[bytes, None, None]:
break
continue

self.ws.close()
ws.close()

def synthesize_streaming(
self,
Expand All @@ -198,17 +200,19 @@ def synthesize_streaming(
"""Synthesize a stream of text chunks. Useful when piping LLM output."""
self._reset_state()
self._connect()
ws = self.ws
assert ws is not None # _connect() raises unless the socket opened

def send_text():
try:
for text_chunk in text_stream:
if text_chunk.strip():
payload = self._create_payload(text_chunk, continue_stream=continue_stream)
self.ws.send(json.dumps(payload))
ws.send(json.dumps(payload))

if auto_flush:
flush_payload = self._create_payload("", flush=True)
self.ws.send(json.dumps(flush_payload))
ws.send(json.dumps(flush_payload))
except Exception as e:
self.error_queue.put(e)

Expand All @@ -230,17 +234,19 @@ def send_text():
break
continue

self.ws.close()
ws.close()

def send_text_chunk(self, text: str, continue_stream: bool = True, flush: bool = False):
if not self.is_connected:
raise Exception("WebSocket not connected")
assert self.ws is not None # is_connected implies the socket is set
payload = self._create_payload(text, continue_stream=continue_stream, flush=flush)
self.ws.send(json.dumps(payload))

def flush_buffer(self):
if not self.is_connected:
raise Exception("WebSocket not connected")
assert self.ws is not None # is_connected implies the socket is set
payload = self._create_payload("", flush=True)
self.ws.send(json.dumps(payload))

Expand Down
Loading