Skip to content

Commit

Permalink
Proper URL encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybchris committed Apr 15, 2024
1 parent 26c9964 commit 05c545a
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions hume/_voice/mixins/chat_mixin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
import logging
import urllib.parse
from contextlib import asynccontextmanager
from typing import AsyncIterator, ClassVar, Optional

Expand Down Expand Up @@ -39,23 +39,24 @@ async def connect(
"""Connect to the voice API."""
uri_base = self._build_endpoint("evi", "chat", Protocol.WS)

# TODO: Use proper query param formatting
uri = (
f"{uri_base}"
f"?speed_ratio={speed_ratio}"
f"&postprocess={json.dumps(self.DEFAULT_POSTPROCESS)}"
f"&cut_ms={self.DEFAULT_CUT_MS}"
f"&encoding={self.DEFAULT_ENCODING_NAME}"
f"&channels={VoiceSocket.N_CHANNELS}"
f"&sample_rate={VoiceSocket.SAMPLE_RATE}"
f"&language_model_type={self.DEFAULT_LANGUAGE_MODEL_TYPE}"
f"&language_model_temperature={self.DEFAULT_LANGUAGE_MODEL_TEMPERATURE}"
f"&generate_short_response={json.dumps(self.DEFAULT_GENERATE_SHORT_RESPONSE)}"
f"&no_binary={json.dumps(self.DEFAULT_NO_BINARY)}"
f"&send_gap_ms={self.DEFAULT_SEND_GAP_MS}"
f"&sensitive_interruptibility={json.dumps(self.DEFAULT_SENSITIVE_INTERRUPTIBILITY)}"
f"&tts={tts_type}"
)
params = {
"speed_ratio": speed_ratio,
"postprocess": self.DEFAULT_POSTPROCESS,
"cut_ms": self.DEFAULT_CUT_MS,
"encoding": self.DEFAULT_ENCODING_NAME,
"channels": VoiceSocket.N_CHANNELS,
"sample_rate": VoiceSocket.SAMPLE_RATE,
"language_model_type": self.DEFAULT_LANGUAGE_MODEL_TYPE,
"language_model_temperature": self.DEFAULT_LANGUAGE_MODEL_TEMPERATURE,
"generate_short_response": self.DEFAULT_GENERATE_SHORT_RESPONSE,
"no_binary": self.DEFAULT_NO_BINARY,
"send_gap_ms": self.DEFAULT_SEND_GAP_MS,
"sensitive_interruptibility": self.DEFAULT_SENSITIVE_INTERRUPTIBILITY,
"tts": tts_type,
}

encoded_params = urllib.parse.urlencode(params)
uri = f"{uri_base}?{encoded_params}"

if config_id is not None:
uri += f"&config_id={config_id}"
Expand Down

0 comments on commit 05c545a

Please sign in to comment.