## 環境安裝 ``` #optimum安裝 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple optimum auto-gptq pip install optimum[exporters] pip install pyaudio pip install tqdm pip install soundfile pip install SpeechRecognition pip install psutil pip install openai-whisper pip install ffmpeg-python pip install torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 --index-url https://download.pytorch.org/whl/cpu sudo apt install ffmpeg #新增環境變數 export QAIC_LIBRARY_PATH=/opt/qti-aic/dev/python:/opt/qti-aic/dev/lib/x86_64/ ``` ## 從 Huggingface 下載並導出 Whisper 模型 ``` optimum-cli export onnx --model openai/whisper-tiny.en whisper-models --cache_dir ./cache ``` ## 下載whisper-onnx-cpu的python code ``` git clone https://github.com/PINTO0309/whisper-onnx-cpu.git ``` ## 在whisper-onnx-cpu下轉譯音檔 model有分 tiny base small... 有加.en就是英文專用版本 beam_size越高可以增加處理速度,但緩存要夠好 音檔下載好路徑記得打對 ``` python3 whisper/transcribe.py --mode audio --model tiny.en --audio whisper/TedTalk.mp3 --beam_size 3 ``` 輸入完後會先下載模型,可以看到資料夾多出了tiny.en的模型  接著就會開始慢慢轉譯  最後會存起來  ### Q: 如果輸入同樣的指令再跑一次會報錯? ### A: 因為模型已經下載好了,無法下載同樣的模型 解法一:將下載好的模型刪掉 解法二(適用於要跑同一個模型): 在model.py裡的ort.InferenceSession中,把下載模型的function替換成先前下載好的模型路徑 如果要換模型的話這邊記得改掉   ## 編譯模型(編碼器和解碼器) 這邊編譯.onnx模型會產生出.bin檔,猜測目的是為了再轉成高通晶片的格式,才能調用NPU,但少了qaic_test.patch沒辦法完成這個步驟 ``` /opt/qti-aic/exec/qaic-exec -m=whisper-models/encoder_model.onnx \ -aic-hw -aic-hw-version=2.0 \ -convert-to-fp16 \ -onnx-define-symbol=batch_size,1 -onnx-define-symbol=feature_size,80 -onnx-define-symbol=encoder_sequence_length,3000 \ -onnx-define-symbol="encoder_sequence_length / 2",1500 \ -aic-binary-dir=compiled_tiny.en_encoder_fp16_300 /opt/qti-aic/exec/qaic-exec -m=whisper-models/decoder_model.onnx \ -aic-hw -aic-hw-version=2.0 \ -convert-to-fp16 \ -onnx-define-symbol=batch_size,1 -onnx-define-symbol=decoder_sequence_length,300 -onnx-define-symbol="encoder_sequence_length / 2",1500 \ -aic-binary-dir=compiled_tiny.en_decoder_fp16_300 ``` 編譯出來後會產生這兩個資料夾  ``` git clone https://github.com/PINTO0309/whisper-onnx-cpu.git cp qaic_test.patch whisper-onnx-cpu cp -r compiled_tiny.en_* whisper-onnx-cpu cd whisper-onnx-cpu git apply qaic_test.patch python3 whisper/transcribe.py --mode audio --model tiny.en --audio whisper/TedTalk.mp3 --beam_size 3 ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up