1.开原地址:https://github.com/openai/whisper
https://github.com/guillaumekln/faster-whisper
2.使用场景:语音转文字
3.api封装:
import os import uvicorn from fastapi import FastAPI, UploadFile, File from whisper import load_model app = FastAPI() model = load_model("large") def transcribe_audio(audio_file): if not audio_file.filename.endswith((".wav", ".mp3")): raise ValueError("Invalid audio file. Supported formats: .wav, .mp3") file_path = os.path.join("D:/save", audio_file.filename) with open(file_path, "wb") as f: f.write(audio_file.file.read()) result = model.transcribe(file_path) return result["text"] @app.post("/transcribe") async def transcribe(upload: UploadFile = File(...)): try: transcription = transcribe_audio(upload) return {"transcription": transcription} except Exception as e: return {"error": str(e)} if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=11120)
标签:__,transcribe,whisper,模型,file,import,文本,audio From: https://www.cnblogs.com/AmbitiousMice/p/17508339.html