whisper語音識別部署及WER評價

1.whisper部署

詳細過程可以參照:🏠

創建項目文件夾

mkdir whisper
cd whisper

conda創建虛擬環境

conda create -n py310 python=3.10 -c conda-forge -y

安裝pytorch

pip install --pre torch torchvision torchaudio --extra-index-url 

下載whisper

pip install --upgrade --no-deps --force-reinstall git+https://github.com/openai/whisper.git

安裝相關包

pip install tqdm
pip install numba
pip install tiktoken==0.3.3
brew install ffmpeg

測試一下whispet是否安裝成功(默認識別為中文)

whisper test.wav --model small
#test.wav為自己的測試wav文件,map3也支持 small是指用小模型

whisper識別中文的時候經常會輸出繁體,加入一下參數可以避免:

 whisper test.wav --model small --language zh --initial_prompt "以下是普通話的句子。"
#注意"以下是普通話的句子。"不能隨便修改,只能是這句話才有效果。

2.腳本批量測試

創建test.sh腳本,輸入一下內容,可以實現對某一文件夾下的wav文件逐個中文語音識別。

#!/bin/bash
for ((i=0;i<300;i++));dofile="wav/A13_${i}.wav"if [ ! -f "$file" ];thenbreakfiwhisper "$file" --model medium --output_dir denied --language zh --initial_prompt "以下是普通話的句子。"
done

?實現英文語音識別需要修改為:

#!/bin/bash
for ((i=0;i<300;i++));dofile="en/${i}.wav"if [ ! -f "$file" ];thenbreakfiwhisper "$file" --model small --output_dir denied --language en
done

3.對運行出來的結果進行評測

一般地,語音識別通常采用WER,即詞錯誤率,評估語音識別和文本轉換質量。

這里我們主要采用 github上的開源項目:🌟?編寫的python-wer代碼對結果進行評價。

其中,我們的正確樣本形式為:

?whisper輸出的預測結果形式為:

?因此要對文本進行處理(去空格、去標點符號)后進行wer評價,相關代碼如下:

(可根據具體情況修改calculate_WER)

import sys
import numpydef editDistance(r, h):'''This function is to calculate the edit distance of reference sentence and the hypothesis sentence.Main algorithm used is dynamic programming.Attributes: r -> the list of words produced by splitting reference sentence.h -> the list of words produced by splitting hypothesis sentence.'''d = numpy.zeros((len(r)+1)*(len(h)+1), dtype=numpy.uint8).reshape((len(r)+1, len(h)+1))for i in range(len(r)+1):d[i][0] = ifor j in range(len(h)+1):d[0][j] = jfor i in range(1, len(r)+1):for j in range(1, len(h)+1):if r[i-1] == h[j-1]:d[i][j] = d[i-1][j-1]else:substitute = d[i-1][j-1] + 1insert = d[i][j-1] + 1delete = d[i-1][j] + 1d[i][j] = min(substitute, insert, delete)return ddef getStepList(r, h, d):'''This function is to get the list of steps in the process of dynamic programming.Attributes: r -> the list of words produced by splitting reference sentence.h -> the list of words produced by splitting hypothesis sentence.d -> the matrix built when calulating the editting distance of h and r.'''x = len(r)y = len(h)list = []while True:if x == 0 and y == 0: breakelif x >= 1 and y >= 1 and d[x][y] == d[x-1][y-1] and r[x-1] == h[y-1]: list.append("e")x = x - 1y = y - 1elif y >= 1 and d[x][y] == d[x][y-1]+1:list.append("i")x = xy = y - 1elif x >= 1 and y >= 1 and d[x][y] == d[x-1][y-1]+1:list.append("s")x = x - 1y = y - 1else:list.append("d")x = x - 1y = yreturn list[::-1]def alignedPrint(list, r, h, result):'''This funcition is to print the result of comparing reference and hypothesis sentences in an aligned way.Attributes:list   -> the list of steps.r      -> the list of words produced by splitting reference sentence.h      -> the list of words produced by splitting hypothesis sentence.result -> the rate calculated based on edit distance.'''print("REF:", end=" ")for i in range(len(list)):if list[i] == "i":count = 0for j in range(i):if list[j] == "d":count += 1index = i - countprint(" "*(len(h[index])), end=" ")elif list[i] == "s":count1 = 0for j in range(i):if list[j] == "i":count1 += 1index1 = i - count1count2 = 0for j in range(i):if list[j] == "d":count2 += 1index2 = i - count2if len(r[index1]) < len(h[index2]):print(r[index1] + " " * (len(h[index2])-len(r[index1])), end=" ")else:print(r[index1], end=" "),else:count = 0for j in range(i):if list[j] == "i":count += 1index = i - countprint(r[index], end=" "),print("\nHYP:", end=" ")for i in range(len(list)):if list[i] == "d":count = 0for j in range(i):if list[j] == "i":count += 1index = i - countprint(" " * (len(r[index])), end=" ")elif list[i] == "s":count1 = 0for j in range(i):if list[j] == "i":count1 += 1index1 = i - count1count2 = 0for j in range(i):if list[j] == "d":count2 += 1index2 = i - count2if len(r[index1]) > len(h[index2]):print(h[index2] + " " * (len(r[index1])-len(h[index2])), end=" ")else:print(h[index2], end=" ")else:count = 0for j in range(i):if list[j] == "d":count += 1index = i - countprint(h[index], end=" ")print("\nEVA:", end=" ")for i in range(len(list)):if list[i] == "d":count = 0for j in range(i):if list[j] == "i":count += 1index = i - countprint("D" + " " * (len(r[index])-1), end=" ")elif list[i] == "i":count = 0for j in range(i):if list[j] == "d":count += 1index = i - countprint("I" + " " * (len(h[index])-1), end=" ")elif list[i] == "s":count1 = 0for j in range(i):if list[j] == "i":count1 += 1index1 = i - count1count2 = 0for j in range(i):if list[j] == "d":count2 += 1index2 = i - count2if len(r[index1]) > len(h[index2]):print("S" + " " * (len(r[index1])-1), end=" ")else:print("S" + " " * (len(h[index2])-1), end=" ")else:count = 0for j in range(i):if list[j] == "i":count += 1index = i - countprint(" " * (len(r[index])), end=" ")print("\nWER: " + result)return resultdef wer(r, h):"""This is a function that calculate the word error rate in ASR.You can use it like this: wer("what is it".split(), "what is".split()) """# build the matrixd = editDistance(r, h)# find out the manipulation stepslist = getStepList(r, h, d)# print the result in aligned wayresult = float(d[len(r)][len(h)]) / len(r) * 100result = str("%.2f" % result) + "%"result=alignedPrint(list, r, h, result)return result# 計算總WER
def calculate_WER():with open("whisper_out.txt", "r") as f:text1_list = [i[11:].strip("\n") for i in f.readlines()]with open("A13.txt", "r") as f:text2_orgin_list = [i[11:].strip("\n") for i in f.readlines()]total_distance = 0total_length = 0WER=0symbols = ",@#¥%……&*()——+~!{}【】;‘:“”‘。?》《、"# calculate distance between each pair of textsfor i in range(len(text1_list)):match1 = re.search('[\u4e00-\u9fa5]', text1_list[i])if match1:index1 = match1.start()else:index1 = len(text1_list[i])match2 = re.search('[\u4e00-\u9fa5]', text2_orgin_list[i])if match2:index2 = match2.start()else:index2 = len( text2_orgin_list[i])result1=  text1_list[i][index1:]result1= result1.translate(str.maketrans('', '', symbols))result2=  text2_orgin_list[i][index2:]result2=result2.replace(" ", "")print(result1)print(result2)result=wer(result1,result2)WER+=float(result.strip('%')) / 100WER=WER/len(text1_list)print("總WER:", WER)print("總WER:", WER.__format__('0.2%'))
calculate_WER()

評價結果形如:

4.與paddlespeech的測試對比:

數據集

數據量

paddle

(中英文分開)

paddle

(同一模型)

whisper(small)

(同一模型)

whisper(medium)

(同一模型)

zhthchs30

(中文錯字率)

250

11.61%

45.53%

24.11%

13.95%

LibriSpeech

(英文錯字率)

125

7.76%

50.88%

9.31%

9.31%

5.測試所用數據集

自己處理過的開源wav數據

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/41315.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/41315.shtml
英文地址,請注明出處:http://en.pswp.cn/news/41315.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

智慧工地云平臺源碼——塔機監控系統

智慧工地概念 智慧工地是一種嶄新的工程全生命周期管理理念&#xff0c;是指運用信息化手段&#xff0c;通過對工程項目進行精確設計和施工模擬&#xff0c;圍繞施工過程管理&#xff0c;建立互聯協同、智能生產、科學管理的施工項目信息化生態圈&#xff0c;并將此數據在虛擬…

鴿王-稚暉君,“遠征”A1啟程

看到這篇文章的人&#xff0c;想必對野生鋼鐵俠-稚暉君&#xff0c;都有所了解。作為華為的天才少年&#xff0c;獲得了很多的榮譽&#xff0c;作為B站有名的鴿王&#xff0c;在沉浮一段時間后終于要帶著新的東西和大家見面了。動態-嗶哩嗶哩https://b23.tv/Jv7tIjg 眾所周知&a…

網絡通信原理TCP字段解析(第四十七課)

字段含義Source Port(源端口號)源端口,標識哪

vueuse常用方法

useDateFormat 時間格式化 <script setup lang"ts">import { useNow, useDateFormat } from vueuse/coreconst formatted useDateFormat(useNow(), YYYY-MM-DD HH:mm:ss)</script><template><div>{{ formatted }}</div> </templa…

el-input添加自定義指令只允許輸入中文/英文/數字,兼容輸入法事件

省流 script: directives: {regexp: {inserted: (el, binding, vnode) > {let composition falseconst formatValue function (e) {if (composition) return// vnode.componentInstance組件實例vnode.componentInstance.$emit(input, e.target.value.replace(/[^\u4e00-…

Python學習筆記_基礎篇(十二)_nmap使用及案例

nmap概念及功能 概念 NMap&#xff0c;也就是Network Mapper&#xff0c;最早是Linux下的網絡掃描和嗅探工具包。 nmap是一個網絡連接端掃描軟件&#xff0c;用來掃描網上電腦開放的網絡連接端。確定哪些服務運行在哪些連接端&#xff0c;并且推斷計算機運行哪個操作系統&am…

ChatGPT在智能音樂推薦和個性化播放列表中的應用如何?

智能音樂推薦和個性化播放列表是音樂流媒體領域中的重要應用&#xff0c;可以幫助用戶發現新音樂、定制自己的音樂體驗&#xff0c;并提升音樂平臺的用戶滿意度。ChatGPT作為一種先進的自然語言處理模型&#xff0c;可以在智能音樂推薦和個性化播放列表領域發揮重要作用。本文將…

神經網絡基礎-神經網絡補充概念-56-遷移學習

遷移學習&#xff08;Transfer Learning&#xff09;是一種機器學習技術&#xff0c;旨在將在一個任務上學到的知識或模型遷移到另一個相關任務上&#xff0c;以提高新任務的性能。遷移學習的核心思想是通過利用源領域&#xff08;source domain&#xff09;的知識來改善目標領…

微信小程序全局事件訂閱eventBus

微信小程序全局事件訂閱 在Vue開發中&#xff0c;我們可能用過eventBus來解決全局范圍內的事件訂閱及觸發邏輯&#xff0c;在微信小程序的開發中我們可能也也會遇到同樣的需求&#xff0c;那么我們嘗試下在小程序&#xff08;原生小程序開發&#xff09;中實現類似eventBus的事…

大模型技術實踐(一)|ChatGLM2-6B基于UCloud UK8S的創新應用

近半年來&#xff0c;通過對多款主流大語言模型進行了調研&#xff0c;我們針對其訓練方法和模型特點進行逐一分析&#xff0c;方便大家更加深入了解和使用大模型。本文將重點分享ChatGLM2-6B基于UCloud云平臺的UK8S實踐應用。 01各模型結構及特點 自從2017年6月谷歌推出Transf…

FlexTools plugin and 3dWindow plugin for SketchUp Crack

FlexTools v2.3.6 plugin for SketchUp 3dWindow v.4.5 plugin for SketchUp 建筑師和3D藝術家使用FlexTools創建SketchUp門、窗、樓梯和其他建筑元素&#xff0c;具有卓越的速度和控制水平。 SketchUp功能強大但易于使用的擴展。對于在施工圖或建筑圖中使用SketchUp的每個人…

數學建模:論文排版技巧及圖表公式規范制作

Excel 論文樣式提前設置利用題注和表注能夠自動排序mac m1 mathtype沒有永久版&#xff0c;淘寶價格比官網低 編輯公式注意事項&#xff1a; 1、公式居中&#xff0c;標號為英文狀態輸入并右對齊。 2、中英文狀態下&#xff0c;對應字母的狀態不同&#xff0c;請合理選擇。 3、…

034_小馳私房菜_[問題復盤] Qcom平臺,某些三方相機拍照旋轉90度

全網最具價值的Android Camera開發學習系列資料~ 作者:8年Android Camera開發,從Camera app一直做到Hal和驅動~ 歡迎訂閱,相信能擴展你的知識面,提升個人能力~ 【一、問題】 某些三方相機,預覽正常,拍照旋轉90度 【二、問題排查】 1 ) HAL這邊Jpeg編碼數據在哪個地方…

C# 隨機法求解線性規劃問題 蒙特卡洛

線性規劃問題: max3x12x2 x12x2<5 2x1x2<4 4x13x2<9 x1>0 x2>0 正確的結果:x11.5; x21, max z6.5 Random random1 new Random(DateTime.Now.Millisecond);Random random2 new Random(DateTime.Now.Millisecond*DateTime.Now.Millisecond);double max-9999,x1…

Pycharm與Anaconda Python的開發環境搭建

目錄 一&#xff1a;下載 二&#xff1a;安裝python 三&#xff1a;設置Pycharm 一&#xff1a;下載 下載Anaconda&#xff1a; Anaconda | The World’s Most Popular Data Science Platform 安裝好以后&#xff0c;設置一下環境變量&#xff1a; 打開命令行&#xff0c…

UI界面設置

文章目錄 1. 修改 share.html 內容如下&#xff1a;2. 修改 html 文件格式為 utf-83.保存&#xff0c;運行程序4. 訪問頁面 1. 修改 share.html 內容如下&#xff1a; <!DOCTYPE html><html> <head><meta charset"utf-8"><title>1v1屏…

uniapp 官方擴展組件 uni-combox 實現:只能選擇不能手寫(輸入中支持過濾顯示下拉列表)

uniapp 官方擴展組件 uni-combox 實現&#xff1a;只能選擇不能手寫&#xff08;輸入中支持過濾顯示下拉列表&#xff09; uni-comboxuni-combox 原本支持&#xff1a;問題&#xff1a; 改造源碼參考資料 uni-combox uni-combox 原本支持&#xff1a; 下拉選擇。輸入關鍵字&am…

【002】學習筆記之typescript的【任意類型】

任意類型 頂級類型&#xff1a;any類型和 unknown 類型 any類型 聲明變量的時候沒有指定任意類型默認為any任意類型都可以賦值給any&#xff0c;不需要檢查類型。也是他的弊端如果使用any 就失去了TS類型檢測的作用 unknown 類型 TypeScript 3.0中引入的 unknown 類型也被認為…

WSL2 ubuntu子系統換源

文章目錄 1.直接編輯/etc/apt/sources.list文件&#xff08;需要使用 sudo&#xff09;:2.將文件中的內容刪除&#xff0c;將以下對應版本鏡像源復制到里面。ubuntu的鏡像源 3.更新 1.直接編輯/etc/apt/sources.list文件&#xff08;需要使用 sudo&#xff09;: 將原文件做備份…

Leetcode Top 100 Liked Questions(序號53~74)

53. Maximum Subarray 題意&#xff1a;一個數組&#xff0c;找到和最大的子串 我的思路 我記得好像On的動態規劃來做的&#xff1f;但是想不起來了&#xff0c;先死做&#xff0c;用的前綴和——TLE超時 那就只能想想dp怎么做了 假設dp[i]表示的是以 i 為右端點的最大的…