头图

0.基础环境

类别:笔记本
型号:中国长城 NF14C
硬件平台:飞腾处理器FT2000(ArmV8 指令集)
系统:银河麒麟操作系统 V10 SP1(2303)

关键词:
信创,麒麟系统,linux,飞腾,arm,aarch,arm64,whisper,LLM,人工智能,大语言模型

1.需求背景

在日常的会议中,为了方便、准确记录会议精神或者一些其他的语音识别成文本的需求,我们在Windows下有很多解决方案,但大语言模型流行的今天,利用大语言模型来识别更为精准。通过检索请多资料,目前OpenAI开放的Whisper模型已升级至large-v2版本,效果非常好(目前我只以普通话为准进行试验,后续如果是方言,可能需要进和本地化训练,不在本文撰写范围)

2.录音

你可以随意下载一个Mp3(如果是试验,不宜过长)。我这里是利用系统的录音软件临时录了一个小片DEMO
图片.png

3.python3的准备

利用which python确认是否是python3.9以上版本,默认正常自带2.7

3.1pyenv版本管理

pyenv是轻量级的python多版本管理工具,非conda这一类的虚拟环境,但可以方便切换系统版本需要,满足本文需求

curl https://pyenv.run | bash

编辑.bashrc,vim ~/.bashrc,在尾部追加下面的内容

export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

再重新打开命令行,进行python安装详细操作请检索pyenv相关资料

pyenv install --list #显示可安装版本
pyenv install -v 3.9.16 #安装指定版本
pyenv global 3.9.16 #切换

补充卸载命令

pyenv uninstall 2.7.15

3.whisper的安装与使用

项目地址:https://github.com/openai/whisper
图片.png

3.1安装

详细过程与用法参照项目官方github.coom页面

pip install -U openai-whisper #安装

安装ffmpeg

sudo apt install ffmpeg

安装rust相关

pip install setuptools-rust

3.2使用

在实际使用中,whisper需要利用到GPU,因为本机没 GPU,用CPU能解决问题,但过程较慢,大家可以选择小一点的模型
图片.png
但除large,large-v2外,其他仅支持英语

whisper test.mp3 --language zh --model large-v2 #指定语言可以减少模型检测时间,支持flac,wav,ape许多的音频格式
top | grep "whisper"

对应语言代码

"en": "english",
    "zh": "chinese",
    "de": "german",
    "es": "spanish",
    "ru": "russian",
    "ko": "korean",
    "fr": "french",
    "ja": "japanese",
    "pt": "portuguese",
    "tr": "turkish",
    "pl": "polish",
    "ca": "catalan",
    "nl": "dutch",
    "ar": "arabic",
    "sv": "swedish",
    "it": "italian",
    "id": "indonesian",
    "hi": "hindi",
    "fi": "finnish",
    "vi": "vietnamese",
    "he": "hebrew",
    "uk": "ukrainian",
    "el": "greek",
    "ms": "malay",
    "cs": "czech",
    "ro": "romanian",
    "da": "danish",
    "hu": "hungarian",
    "ta": "tamil",
    "no": "norwegian",
    "th": "thai",
    "ur": "urdu",
    "hr": "croatian",
    "bg": "bulgarian",
    "lt": "lithuanian",
    "la": "latin",
    "mi": "maori",
    "ml": "malayalam",
    "cy": "welsh",
    "sk": "slovak",
    "te": "telugu",
    "fa": "persian",
    "lv": "latvian",
    "bn": "bengali",
    "sr": "serbian",
    "az": "azerbaijani",
    "sl": "slovenian",
    "kn": "kannada",
    "et": "estonian",
    "mk": "macedonian",
    "br": "breton",
    "eu": "basque",
    "is": "icelandic",
    "hy": "armenian",
    "ne": "nepali",
    "mn": "mongolian",
    "bs": "bosnian",
    "kk": "kazakh",
    "sq": "albanian",
    "sw": "swahili",
    "gl": "galician",
    "mr": "marathi",
    "pa": "punjabi",
    "si": "sinhala",
    "km": "khmer",
    "sn": "shona",
    "yo": "yoruba",
    "so": "somali",
    "af": "afrikaans",
    "oc": "occitan",
    "ka": "georgian",
    "be": "belarusian",
    "tg": "tajik",
    "sd": "sindhi",
    "gu": "gujarati",
    "am": "amharic",
    "yi": "yiddish",
    "lo": "lao",
    "uz": "uzbek",
    "fo": "faroese",
    "ht": "haitian creole",
    "ps": "pashto",
    "tk": "turkmen",
    "nn": "nynorsk",
    "mt": "maltese",
    "sa": "sanskrit",
    "lb": "luxembourgish",
    "my": "myanmar",
    "bo": "tibetan",
    "tl": "tagalog",
    "mg": "malagasy",
    "as": "assamese",
    "tt": "tatar",
    "haw": "hawaiian",
    "ln": "lingala",
    "ha": "hausa",
    "ba": "bashkir",
    "jw": "javanese",
    "su": "sundanese",

第一次执行会需要下载模型,约2.87GB,需要耐心等待。模型下载后,进行识别,资源监控如下图
图片.png
最后的识别效果,准确无误
图片.png

3.3 通过迅雷离线下载whisper模型文件

3.2中,使用到哪个离线,whisper会自己去下载,但由于众所周知的原因,下载很容易被中断,一旦中断,就需要重新再来,浪费时间和生命。因此想到用迅雷加速下载,节约生命,多留出时间陪老婆、孩子、父母。
首先无论是Windows还是Linux,下载下来的文件均放在"用户主目录/.cache/whisper"中,因此,我们只要将文件下载下来复制到该位置即可。
获取最新的所有模型下载地址,点开https://github.com/openai/whisper/blob/main/whisper/__init__.py


_MODELS = {
    "tiny.en": "https://openaipublic.azureedge.net/main/whisper/models/d3dd57d32accea0b295c96e26691aa14d8822fac7d9d27d5dc00b4ca2826dd03/tiny.en.pt",
    "tiny": "https://openaipublic.azureedge.net/main/whisper/models/65147644a518d12f04e32d6f3b26facc3f8dd46e5390956a9424a650c0ce22b9/tiny.pt",
    "base.en": "https://openaipublic.azureedge.net/main/whisper/models/25a8566e1d0c1e2231d1c762132cd20e0f96a85d16145c3a00adf5d1ac670ead/base.en.pt",
    "base": "https://openaipublic.azureedge.net/main/whisper/models/ed3a0b6b1c0edf879ad9b11b1af5a0e6ab5db9205f891f668f8b0e6c6326e34e/base.pt",
    "small.en": "https://openaipublic.azureedge.net/main/whisper/models/f953ad0fd29cacd07d5a9eda5624af0f6bcf2258be67c92b79389873d91e0872/small.en.pt",
    "small": "https://openaipublic.azureedge.net/main/whisper/models/9ecf779972d90ba49c06d968637d720dd632c55bbf19d441fb42bf17a411e794/small.pt",
    "medium.en": "https://openaipublic.azureedge.net/main/whisper/models/d7440d1dc186f76616474e0ff0b3b6b879abc9d1a4926b7adfa41db2d497ab4f/medium.en.pt",
    "medium": "https://openaipublic.azureedge.net/main/whisper/models/345ae4da62f9b3d59415adc60127b97c714f32e89e936602e85993674d08dcb1/medium.pt",
    "large-v1": "https://openaipublic.azureedge.net/main/whisper/models/e4b87e7e0bf463eb8e6956e646f1e277e901512310def2c24bf0e11bd3c28e9a/large-v1.pt",
    "large-v2": "https://openaipublic.azureedge.net/main/whisper/models/81f7c96c852ee8fc832187b0132e569d6c3065a3252ed18e56effd0b6a73e524/large-v2.pt",
    "large-v3": "https://openaipublic.azureedge.net/main/whisper/models/e5b1a55b89c1367dacf97e3e19bfd829a01529dbfdeefa8caeb59b3f1b81dadb/large-v3.pt",
    "large": "https://openaipublic.azureedge.net/main/whisper/models/e5b1a55b89c1367dacf97e3e19bfd829a01529dbfdeefa8caeb59b3f1b81dadb/large-v3.pt",
    "large-v3-turbo": "https://openaipublic.azureedge.net/main/whisper/models/aff26ae408abcba5fbf8813c21e62b0941638c5f6eebfb145be0c9839262a19a/large-v3-turbo.pt",
    "turbo": "https://openaipublic.azureedge.net/main/whisper/models/aff26ae408abcba5fbf8813c21e62b0941638c5f6eebfb145be0c9839262a19a/large-v3-turbo.pt",
}

下载最新版本的迅雷(测试用过迅雷12),即可将大模型下载下来,可以断点续传,也可以做到极速。

写在最后

本人用的这台长城的笔记本基于飞腾Ft2000,在使用conda pip时有问题,因此考虑到系统自带了python2.7,所以在就利用pyenv切换了一下python 3.9.16的版本,大家可以尝试其他版本。

另外,还有一个buzz的开源软件(基于whisper),提供GUI,没有官方版本,只能后续有时间再补上,//todo

麒麟系统专栏:
https://segmentfault.com/blog/kylinos
文章发表在SegmentFault
联系邮箱:1179611323@qq.com
群:662512340
发行日志:
20230929 首发 中秋快乐
20241206 更新 whisper模型离线下载


码上世界
79 声望290 粉丝

码农极客,2004年接触Linux世界。爱技术的IT的男