Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 11, 2023
1 parent a6dd786 commit a8fdc2f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ledfx/api/websocket.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncio
import binascii
import json
import logging
import struct
import binascii
from concurrent import futures
from base64 import b64decode
from concurrent import futures

import numpy as np
import voluptuous as vol
Expand Down Expand Up @@ -316,13 +316,18 @@ def audio_stream_data_base64_handler(self, message):
except binascii.Error:
_LOGGER.info("Incorrect base64 padding.")
except Exception as err:
_LOGGER.exception("Unexpected Exception in base64 decoding: %s", err)
_LOGGER.exception(
"Unexpected Exception in base64 decoding: %s", err
)
else:
fmt = "<%dh" % (len(decoded) // 2)
data = list(struct.unpack(fmt, decoded))
# Minimum value is -32768 for signed, so that's why if the number is negative,
# it is divided by 32768 when converting to float.
data = np.array([d/MAX_VAL if d >= 0 else d/(MAX_VAL+1) for d in data], dtype=np.float32)
data = np.array(
[d / MAX_VAL if d >= 0 else d / (MAX_VAL + 1) for d in data],
dtype=np.float32,
)
ACTIVE_AUDIO_STREAM.data = data


Expand Down

0 comments on commit a8fdc2f

Please sign in to comment.