clementruhm commited on
Commit
b5433b4
1 Parent(s): 8749790

vc_service_request: introduce free tier

Browse files
Files changed (1) hide show
  1. vc_service_request.py +8 -7
vc_service_request.py CHANGED
@@ -51,18 +51,18 @@ def prepare_audio(audio: Tuple[int, np.ndarray]) -> np.ndarray:
51
  return wav
52
 
53
 
54
- def create_signature() -> str:
55
  """
56
  helper function that creates signature,
57
  required to authentificate the request
58
  """
59
  int_time = int(time.time() / 1000)
60
- signature_input = (os.environ["api_secret"] + str(int_time)).encode()
61
  signature = hashlib.sha256(signature_input).hexdigest()
62
  return signature
63
 
64
 
65
- async def async_service_request(source: np.ndarray, target: np.ndarray) -> np.ndarray:
66
  ssl_context = ssl.create_default_context()
67
 
68
  async with websockets.connect(
@@ -71,8 +71,8 @@ async def async_service_request(source: np.ndarray, target: np.ndarray) -> np.nd
71
  request_dict = {
72
  "source": base64.b64encode(source.tobytes()).decode("utf-8"),
73
  "target": base64.b64encode(target.tobytes()).decode("utf-8"),
74
- "api_key": os.environ["api_key"],
75
- "signature": create_signature(),
76
  }
77
  request = json.dumps(request_dict)
78
  await websocket.send(request)
@@ -94,7 +94,8 @@ async def async_service_request(source: np.ndarray, target: np.ndarray) -> np.nd
94
 
95
 
96
  def vc_service_request(
97
- source_audio: Tuple[int, np.ndarray], target_audio: Tuple[int, np.ndarray]
 
98
  ) -> Tuple[int, np.ndarray]:
99
  """
100
  prepares audio (has to be 16khz mono)
@@ -108,5 +109,5 @@ def vc_service_request(
108
  # input is way too long, dont return anything
109
  return
110
 
111
- res = asyncio.run(async_service_request(src, tgt))
112
  return 16000, res
 
51
  return wav
52
 
53
 
54
+ def create_signature(api_secret: str) -> str:
55
  """
56
  helper function that creates signature,
57
  required to authentificate the request
58
  """
59
  int_time = int(time.time() / 1000)
60
+ signature_input = (api_secret + str(int_time)).encode()
61
  signature = hashlib.sha256(signature_input).hexdigest()
62
  return signature
63
 
64
 
65
+ async def async_service_request(source: np.ndarray, target: np.ndarray, api_key: str, api_secret: str) -> np.ndarray:
66
  ssl_context = ssl.create_default_context()
67
 
68
  async with websockets.connect(
 
71
  request_dict = {
72
  "source": base64.b64encode(source.tobytes()).decode("utf-8"),
73
  "target": base64.b64encode(target.tobytes()).decode("utf-8"),
74
+ "api_key": api_key,
75
+ "signature": create_signature(api_secret),
76
  }
77
  request = json.dumps(request_dict)
78
  await websocket.send(request)
 
94
 
95
 
96
  def vc_service_request(
97
+ source_audio: Tuple[int, np.ndarray], target_audio: Tuple[int, np.ndarray],
98
+ api_key: str, api_secret: str,
99
  ) -> Tuple[int, np.ndarray]:
100
  """
101
  prepares audio (has to be 16khz mono)
 
109
  # input is way too long, dont return anything
110
  return
111
 
112
+ res = asyncio.run(async_service_request(src, tgt, api_key, api_secret))
113
  return 16000, res