bugfix
This commit is contained in:
parent
07627e0648
commit
642e2f1ab7
@ -1,4 +0,0 @@
|
||||
path = params_kw.get('audiofile')
|
||||
print(f'whisper.generate.dspy, {params_kw=}, {file_realpath=}, {stt_engine=}' )
|
||||
x = await stt_engine.stt(file_realpath(path))
|
||||
return x
|
@ -7,38 +7,38 @@ import whisper
|
||||
|
||||
# 编码
|
||||
def base64_encode(text):
|
||||
text_bytes = text.encode('utf-8')
|
||||
encoded_bytes = base64.b64encode(text_bytes)
|
||||
encoded_text = encoded_bytes.decode('utf-8')
|
||||
return encoded_text
|
||||
text_bytes = text.encode('utf-8')
|
||||
encoded_bytes = base64.b64encode(text_bytes)
|
||||
encoded_text = encoded_bytes.decode('utf-8')
|
||||
return encoded_text
|
||||
|
||||
# 解码
|
||||
def base64_decode(encoded_text):
|
||||
encoded_bytes = encoded_text.encode('utf-8')
|
||||
decoded_bytes = base64.b64decode(encoded_bytes)
|
||||
decoded_text = decoded_bytes.decode('utf-8')
|
||||
return decoded_text
|
||||
encoded_bytes = encoded_text.encode('utf-8')
|
||||
decoded_bytes = base64.b64decode(encoded_bytes)
|
||||
decoded_text = decoded_bytes.decode('utf-8')
|
||||
return decoded_text
|
||||
|
||||
class WhisperBase:
|
||||
def __init__(self):
|
||||
model_name = get_definition('whisper_model')
|
||||
model_name = get_definition('whisper_model')
|
||||
self.model = whisper.load_model(model_name)
|
||||
|
||||
def _stt(self, filepath):
|
||||
pass
|
||||
pass
|
||||
|
||||
stt = awaitify(_stt)
|
||||
|
||||
class WhisperFile(WhisperBase):
|
||||
def _stt(self, filepath):
|
||||
return self.model.transcribe(filepath)
|
||||
def _stt(self, filepath):
|
||||
return self.model.transcribe(filepath)
|
||||
|
||||
|
||||
class WhisperBase64(WhisperBase):
|
||||
def _stt(self, audio_base64):
|
||||
raw = base64.decode(audio_base64)
|
||||
ndarr = np.frombuffer(raw, dtype=np.float32)
|
||||
return self.model.transcribe(raw)
|
||||
def _stt(self, audio_base64):
|
||||
raw = base64.decode(audio_base64)
|
||||
ndarr = np.frombuffer(raw, dtype=np.float32)
|
||||
return self.model.transcribe(raw)
|
||||
|
||||
g = ServerEnv()
|
||||
g.whisper_engine = WhisperBase64()
|
||||
|
Loading…
Reference in New Issue
Block a user