🚀 Whisper TFLite模型:用于F-Droid上的Whisper应用
本项目提供适用于F-Droid平台上Whisper应用的TFLite模型。“转录 - 翻译” 模型为 “serving_transcribe” 和 “serving_translate” 提供了签名,以强制模型执行特定操作。
🚀 快速开始
转录和翻译功能代码示例
以下代码展示了如何使用模型进行转录和翻译操作:
@tf.function(
input_signature=[
tf.TensorSpec((1, 80, 3000), tf.float32, name="input_features"),
],
)
def transcribe(self, input_features):
outputs = self.model.generate(
input_features,
max_new_tokens=450,
return_dict_in_generate=True,
forced_decoder_ids=[[2, 50359], [3, 50363]],
)
return {"sequences": outputs["sequences"]}
@tf.function(
input_signature=[
tf.TensorSpec((1, 80, 3000), tf.float32, name="input_features"),
],
)
def translate(self, input_features):
outputs = self.model.generate(
input_features,
max_new_tokens=450,
return_dict_in_generate=True,
forced_decoder_ids=[[2, 50358], [3, 50363]],
)
return {"sequences": outputs["sequences"]}
指定特定语言转录和翻译
若要强制对特定语言进行转录,可按如下方式设置解码器ID:
def transcribe(self, input_features):
outputs = self.model.generate(
input_features,
max_new_tokens=450,
return_dict_in_generate=True,
forced_decoder_ids=[[1, 50261], [2, 50359], [3, 50363]],
)
return {"sequences": outputs["sequences"]}
def translate(self, input_features):
outputs = self.model.generate(
input_features,
max_new_tokens=450,
return_dict_in_generate=True,
forced_decoder_ids=[[1, 50261], [2, 50358], [3, 50363]],
)
return {"sequences": outputs["sequences"]}
(语言代码可参考:https://github.com/woheller69/whisperIME/blob/master/app/src/main/java/com/whispertflite/utils/InputLang.java)
📄 许可证
本项目采用MIT许可证。