hume-python-sdk
hume-python-sdk copied to clipboard
evi-python-example got 403
when I run evi-python-example, I always get 403 websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 403
client = HumeVoiceClient(api_key=HUME_API_KEY) client = HumeVoiceClient(api_key=access_token)
no matter I use HUME_API_KEY(get from https://beta.hume.ai/settings/keys) or access_token (get from https://api.hume.ai/oauth2-cc/token), it's always return "403"
code:
from hume import HumeVoiceClient, MicrophoneInterface
import asyncio
HUME_API_KEY = "my hume api key from https://beta.hume.ai/settings/keys"
HUME_CLIENT_SECRET = "my Secret key from https://beta.hume.ai/settings/keys "
HUME_CONFIG_ID = "my config_id from https://beta.hume.ai/voice/config"
def get_access_token():
import base64
import requests
# Base64 encode API Key and Client Secret
client_id = f"{HUME_API_KEY}:{HUME_CLIENT_SECRET}"
encoded_client_id = base64.b64encode(client_id.encode()).decode()
# request access token
url = 'https://api.hume.ai/oauth2-cc/token'
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': f'Basic {encoded_client_id}'
}
data = {
'grant_type': 'client_credentials'
}
response = requests.post(url, headers=headers, data=data)
data_json = response.json()
print(data_json)
return data_json['access_token']
async def main() -> None:
access_token = get_access_token()
print(access_token)
# Connect and authenticate with Hume
client = HumeVoiceClient(api_key=access_token)
# client = HumeVoiceClient(api_key=HUME_API_KEY)
# Start streaming EVI over your device's microphone and speakers
# config_id=HUME_CONFIG_ID
async with client.connect(config_id=HUME_CONFIG_ID) as socket:
# await MicrophoneInterface.start(socket, device=2)
await MicrophoneInterface.start(socket)
asyncio.run(main())
error msg:
Traceback (most recent call last):
File "/Users/jingwu/anaconda3/envs/humeai-310/lib/python3.10/site-packages/hume/_voice/mixins/chat_mixin.py", line 43, in connect
async with websockets.connect( # type: ignore[attr-defined]
File "/Users/jingwu/anaconda3/envs/humeai-310/lib/python3.10/site-packages/websockets/legacy/client.py", line 629, in __aenter__
return await self
File "/Users/jingwu/anaconda3/envs/humeai-310/lib/python3.10/site-packages/websockets/legacy/client.py", line 647, in __await_impl_timeout__
return await self.__await_impl__()
File "/Users/jingwu/anaconda3/envs/humeai-310/lib/python3.10/site-packages/websockets/legacy/client.py", line 654, in __await_impl__
await protocol.handshake(
File "/Users/jingwu/anaconda3/envs/humeai-310/lib/python3.10/site-packages/websockets/legacy/client.py", line 325, in handshake
raise InvalidStatusCode(status_code, response_headers)
websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 403
my ENV: hume Version: 0.5.1 python : 3.10 Mac:14.4.1 (23E224)