import base64, struct import numpy as np import traceback from fastapi import APIRouter from fastapi.encoders import jsonable_encoder from fastapi.responses import JSONResponse from voice_changer.VoiceChangerManager import VoiceChangerManager from pydantic import BaseModel import threading class VoiceModel(BaseModel): timestamp: int buffer: str class MMVC_Rest_VoiceChanger: def __init__(self, voiceChangerManager:VoiceChangerManager): self.voiceChangerManager = voiceChangerManager self.router = APIRouter() self.router.add_api_route("/test", self.test, methods=["POST"]) self.tlock = threading.Lock() def test(self, voice: VoiceModel): try: timestamp = voice.timestamp buffer = voice.buffer wav = base64.b64decode(buffer) if wav == 0: samplerate, data = read("dummy.wav") unpackedData = data else: unpackedData = np.array(struct.unpack( '<%sh' % (len(wav) // struct.calcsize('