0:00.480–0:09.280
hey everyone welcome to nning IO I'm JDand today we're going to be looking atreal time in browser speech recognition
0:09.280–0:19.720
using web GPU and Transformer JS toactually use speech in the browser sowith that let's go ahead and getstarted all right the first thing that
0:19.720–0:26.160
we're going to do everyone is we'regoing to go to this hugging face spaceand basically what we're going to do is
0:26.160–0:36.520
look at this demo for the whisper webGPO uh it's real time in browserecognition it's using the whisper basewhich is a 73 million parameter speech
0:36.520–0:45.000
recognition mod model and using onx andTransformer JS so you can see that theaudio audio visualizer is already
0:45.000–0:53.960
picking up my voice from the microphoneand uh able to do some kind of uh visualwhat we're going to do is actually load
0:53.960–1:04.159
this model and then we should be able tosee real time uh transcription but whatwe want to showis also that if you go and look at your
1:04.159–1:11.920
network uh right now I have I'm on thiswasm tab and we want to pay attention toboth Fetch and wasm so we're going to go
1:11.920–1:22.680
ahead and look at the model and you cansee it pulled it in really quickly uhcould be uh because it's cached but uh
1:22.680–1:30.079
this was incredibly fast and it'salready doing the the transcription inreal time you can see that it's trying
1:30.079–1:38.560
addpunctuation and uh the token count downhere if we go over to the wasm tab thisall that was loaded it's going
1:38.560–1:48.040
through a worker to establish this andthe size was 4 megabytes so again thiscrazy fast for doing real time uh
1:48.040–1:56.200
transcription in the browser superhelpful if you were trying to do uh likechat based systems where you actually
1:56.200–2:07.439
wanted to have voice in with your chatas without having to go out to open AIor some otherum closed Source or even open source
2:07.439–2:14.560
model that uh requires a backend callright again we didn't fetch anythingfrom our back end this was just loaded
2:14.560–2:22.680
through the browser so now what we'regoing to do is we're going to take thisand we're going to actually look at the
2:22.680–2:34.400
repo and and dig into the code so if youcome over here to Transformers Jsthe thing you want to note is you wanto be on uh the
2:34.400–2:42.680
V3 Branch this is the the new Branchit's still experimental but it's goingto be the next version of Transformer JS
2:42.680–2:46.920
a lot of great examples we've beentrying to go through some of them itfeels like every day they're coming out
2:46.920–2:56.959
with a new demo a new model that they'reable to implement um definitely reallycool stuff so if we look at this example
2:56.959–3:04.239
so we go into Transformer JS examplesand Whisper then we're able to actuallyD dive into this code so what we're
3:04.239–3:08.959
going to do is we're just going to pullthis down get this running on our localmachine and then we'll start digging
3:08.959–3:20.519
into the code so I'm going to use cursorI'm already I already have it pulledown but you can do uh get clone andthen come over
3:20.519–3:34.640
here and just dothis uh we are so I'm in the root sowhat we need to do is go toexamples and then we're going to do web
3:34.640–3:49.680
GPU and go towhisper and we'll do an npminstall and then we'll go ahead and doan npm runDev and what we're going to do is we
3:49.680–4:00.079
have our Local Host here so we can gethis up and running we'll watch reallyquickly if we can gethis uh loaded again super quick you saw
4:00.079–4:06.400
how quickly the the load time was forthat again some of it sometimes it'scashed and the first one's going to be
4:06.400–4:20.280
slower but still reallyimpressive so if we look at some of thecore files in here we have our app whichis the main main file and what we're
4:20.280–4:27.680
going to be looking at is how we'reactually pulling in this worker so thisworker. JS is where we're actually going
4:27.680–4:34.160
to do our Logic for Transformer Js we'repulling in the model we're actuallysending messages back and forth where
4:34.160–4:44.199
you can see right here that as messagesare coming being received we're actuallygoing to be looking for the type of
4:44.199–4:58.479
event that is being pass and then sendthat uh data as wellso you can see most of this is for likeloading there's uh some update which is
4:58.479–5:12.520
where you're updating the textwe're actually going to look and seewhere this is uh is working so if wecontinue down and we are looking at the
5:12.520–5:19.639
recorder this is all the informationabout starting and stopping therecording and then what's Happening Here
5:19.639–5:31.479
is we are actually looking at how thisinformation is being sent with this codeso righthere it's saying as the recording is
5:31.479–5:41.960
coming in we're going to take a blob andchunk it and so then we're going to makea file reader and read those and then
5:41.960–5:57.400
send that on when the file is beingread get that bit information that'sdecoded slice it and then send thoseslices over to our worker so we're
5:57.400–6:06.039
posting the message to generate ourtranscription on the Fly then this isjust our uh our HTML that we're going to
6:06.039–6:15.599
be pullingin so what we'll do is we'll jump overto the worker and then we'll take a lookat how this is actually functioning real
6:15.599–6:21.319
quick everyone if you haven't alreadyplease remember to like And subscribe ithelps more than you know if you have any
6:21.319–6:28.120
questions please leave them in thecomments and with that let's get back toit all right so now that we're in our
6:28.120–6:36.960
worker file we're going to startlooking at how this actually functionsfirst thing is we're loading inTransformers we're going to pull in our
6:36.960–6:49.000
Autokenizer our Auto processor and then uhwhisper and text stream as well as fullso if we look at what we're first doing
6:49.000–6:55.280
we have this class which is our Pipelineand then we're actually using ourinstance where we're getting our model
6:55.280–7:03.240
so we're saying this is our model ID wehave our tokenizer our processor we'reactually getting the model based on our
7:03.240–7:14.280
ID at this point uh we're telling itwhat our dtype is and then specificallywe're using device webGPU and once all of these have processed
7:14.280–7:24.160
uh then our git instance has beenestablished if we scroll down to thebottom we can kind of look at like someof the loader functions so you can see
7:24.160–7:32.840
here there's the load this happens likewhere we're actually posting backmessages to actually see see theprogress bar things like that we're
7:32.840–7:42.639
stablishing some events based on ourmessage and then once the the browser uhor once the model is actually loaded
7:42.639–7:51.159
we're going to be looking for thisgenerate function this function is whatreally is going to be taking the audio
7:51.159–8:00.120
and taking the language and thenactually processing it so the firsthing we'll be doing is saying is if ifprocessing return
8:00.120–8:06.800
if it is not processing then go aheadand set that processing to Truemaintaining State we're actually going
8:06.800–8:13.000
to send a message back to say that we'retrans that the thread is starting sowe're saying start as our status and
8:13.000–8:21.840
then we're actually pulling in ourinstance so again where we set ourtokenizer and our processor and modelwe're actually pulling that from our um
8:21.840–8:29.199
instance and we're starting to actuallyprocess so we have our call backfunction which is going to give us the
8:29.199–8:40.320
output of our post message of update andinformation about our TPS our tokens andour actual output and then we we have
8:40.320–8:51.480
our streamer and we this is where we'reactuallyprocessing our information so what we'resaying is our input we're taking our AO
8:51.480–8:59.440
audio and we're uh putting it throughour processor we then this is ourtranscription our transcription BAS
8:59.440–9:05.560
based on our model and our generatewe're saying we're passing our sameinputs our language and we're actually
9:05.560–9:12.000
streaming the events or streaming theoutput so now we have our tokenizer thisgives us the information that's
9:12.000–9:19.519
displayed in the bottom right of howmany tokens we're actually using andthen we're posting back that chunk of
9:19.519–9:27.519
text as it is complete and so rememberif we are looking at what these postmessages are we're coming back here and
9:27.519–9:39.240
that is the information that is being onmessage received so if we look downtoupdate we're seeing that we're setting
9:39.240–9:50.040
our TPS here as well as uh our messageso our on message right here this iswhere we're being sending theinformation back and then that's how
9:50.040–10:02.800
e're actually passing information downhere so this is where ourTPS is and then uhthe this the rest of the progress bar in
10:02.800–10:14.399
the audio I'm looking fortheactual uh information around the text ohit's right here so on ready we'repassing the information of the text
10:14.399–10:22.240
hat's beingupdated and that's how this works is webasically are taking this informationfrom after after it passes passes
10:22.240–10:29.920
through the model and then right here sobeing generated by the model and thenposting that information back
10:29.920–10:39.639
so it's processing the auto chunk it isaudio chunk and it's uh then convertingthat and doing a transcription on this
10:39.639–10:46.160
generation then it's streaming it'sdoing the tokenizer and posting all thatinformation back all right everyone
10:46.160–10:57.040
that's it for us today what we coveredwas using real time speech recognitionin the browser with web GPU andTransformers JS we're able to dig
10:57.040–11:03.000
through some of the repo and actuallyget their demo up and running and sowith that happy nerding
0:00.480–0:09.280
嗨,大家好,歡迎來到 Nning IO,我是 JD,今天我們將探討在瀏覽器中即時進行語音辨識。
0:09.280–0:19.720
使用 Web GPU 和 Transformer JS 來實際在瀏覽器中使用語音,那麼讓我們開始吧。首先,
0:19.720–0:26.160
我們要做的第一件事是前往這個 Hugging Face 空間,基本上我們要做的就是
0:26.160–0:36.520
查看這個 Whisper WebGPU 的示範,它是瀏覽器中的即時辨識,使用的是 Whisper Base,這是一個擁有 7300 萬參數的語音
0:36.520–0:45.000
辨識模型,並使用 ONNX 和 Transformer JS,所以你可以看到音訊視覺化器已經
0:45.000–0:53.960
從麥克風捕捉到我的聲音,並且能夠進行某種視覺呈現,我們將實際載入
0:53.960–1:04.159
這個模型,然後我們應該能夠看到實時的轉錄,但我們想展示的是,如果你去查看你的
1:04.159–1:11.920
網路,嗯,現在我在這個 WASM 標籤頁,我們要注意 Fetch 和 WASM,所以我們將前往
1:11.920–1:22.680
查看模型,你可以看到它非常快速地載入,嗯,可能是因為它被快取了,但嗯
1:22.680–1:30.079
這非常快速,它已經在即時進行轉錄,你可以看到它正在嘗試
1:30.079–1:38.560
添加標點符號,嗯,以及這裡的計數器,如果我們切換到 WASM 標籤頁,所有這些都已載入,它將
1:38.560–1:48.040
透過一個 worker 來建立這個,大小為 4 MB,所以再次強調,這對於在瀏覽器中進行即時轉錄來說非常快速,超級
1:48.040–1:56.200
在瀏覽器中進行轉錄非常有用,如果你試圖建立基於聊天的系統,而這些系統實際上
1:56.200–2:07.439
希望將語音整合到你的聊天中,而不需要去呼叫 Open AI 或其他某些
2:07.439–2:14.560
閉源或甚至開源的模型,這些模型需要後端呼叫,再次強調,我們沒有從後端獲取任何東西,這只是透過
2:14.560–2:22.680
透過瀏覽器進行,那麼現在我們要做的就是,我們將採取這個方法,並實際查看
2:22.680–2:34.400
儲存庫拿過來,並深入研究程式碼,所以如果你來到這裡的 Transformer JS,你要注意的是,你要在
2:34.400–2:42.680
V3 分支上,這是新的分支,它仍然是實驗性的,但它將是 Transformer JS 的下一個版本
2:42.680–2:46.920
有很多很棒的範例,我們一直在嘗試瀏覽其中一些,感覺他們每天都在推出
2:46.920–2:56.959
新的示範,新的模型,他們能夠實現,嗯,絕對非常酷的東西,所以如果我們查看這個範例
2:56.959–3:04.239
所以我們進入 Transformer JS 範例和 Whisper,然後我們能夠實際深入這個程式碼,所以我們要做的就是將這個
3:04.239–3:08.959
下載下來,在我們的本機機器上運行它,然後我們開始深入研究
3:08.959–3:20.519
程式碼,所以我將使用 Cursor,我已經將它拉下來了,但你可以執行 git clone,然後來到
3:20.519–3:34.640
這裡,只是執行這個,嗯,我在根目錄,所以我們需要做的是前往 examples,然後我們將執行 web
3:34.640–3:49.680
GPU 並前往 whisper,我們將執行 npm install,然後我們將執行 npm run dev,而我們要做的就是
3:49.680–4:00.079
在這裡有我們的本機主機,所以我們可以啟動它,我們將非常快速地查看我們是否能再次載入它,超級快,你看到了
4:00.079–4:06.400
載入時間有多快,再次強調,其中一些有時會被快取,而第一次載入會
4:06.400–4:20.280
較慢,但仍然非常令人印象深刻,所以如果我們查看這裡的一些核心檔案,我們有 app,這是主要的檔案,而我們要
4:20.280–4:27.680
查看的是我們如何實際載入這個 worker,所以這個 worker.js 是我們實際上要
4:27.680–4:34.160
執行 Transformer JS 邏輯的地方,我們正在載入模型,我們實際上正在發送訊息來回傳遞,其中
4:34.160–4:44.199
你可以看到這裡當訊息被接收時,我們實際上會去尋找事件的類型
4:44.199–4:58.479
正在傳遞的事件類型,然後發送該資料,所以你可以看到大部分這都是為了載入,有一些更新,這是
4:58.479–5:12.520
你更新文字的地方,我們實際上將查看並查看這是在哪裡運作,所以如果我們繼續向下查看,我們正在查看
5:12.520–5:19.639
recorder,這是關於開始和停止錄音的所有資訊,然後這裡發生了什麼
5:19.639–5:31.479
是我們實際上正在查看這段程式碼如何發送這些資訊,所以在這裡,它說當錄音
5:31.479–5:41.960
進來時,我們將取得一個 blob 並將其分塊,然後我們將建立一個檔案讀取器並讀取這些,然後
5:41.960–5:57.400
在讀取檔案時發送這些,取得該位元資訊,解碼它,分割它,然後將這些分割部分發送給我們的 worker,所以我們
5:57.400–6:06.039
發送訊息以即時生成我們的轉錄,然後這只是我們將要
6:06.039–6:15.599
載入的 HTML,所以我們將跳轉到 worker,然後我們將查看這實際上是如何即時運作
6:15.599–6:21.319
的,大家,如果你還沒有,請記得按讚和訂閱,這比你知道的更有帮助,如果你有任何
6:21.319–6:28.120
請在留言區留下你的問題,接下來讓我們回到正題,好的,現在我們已經進入我們的
6:28.120–6:36.960
現在我們進入了 worker 檔案,我們將開始查看它實際上的運作方式。第一件事是載入 Transformers,我們將引入 AutoTokenizer、AutoProcessor,以及 whisper 和 text streamer,還有 full。
6:36.960–6:49.000
如果我們查看首先執行的動作,我們有一個類別,這是我們的 Pipeline,然後我們實際上使用我們的執行個體,在這裡取得我們的模型。
6:49.000–6:55.280
所以我們說這是我們的模型 ID,我們有 tokenizer 和 processor,我們實際上是根據我們的 ID 來取得模型。
6:55.280–7:03.240
在這個階段,我們告訴它 dtype 是什麼,然後特別使用 device webGPU,一旦這些都處理完成。
7:03.240–7:14.280
我們的 git 執行個體就建立了。如果我們滾動到底部,我們可以大致查看一些載入函數,所以你可以看到這裡有 load,這發生在我們實際發送訊息回來以查看進度條等事項的地方。
7:14.280–7:24.160
我們根據我們的訊息建立了一些事件,然後一旦瀏覽器或模型實際載入。
7:24.160–7:32.840
這裡有載入,這發生在我們實際回傳訊息以查看進度條等內容時,我們
7:32.840–7:42.639
並處理語言,然後實際處理它,所以我們首先要做的是說,如果處理返回。
7:42.639–7:51.159
如果它不是處理中,則繼續將處理狀態設為 True,維持狀態,我們實際上要發送訊息回來,表示執行緒正在啟動,所以我們將 start 設為狀態。
7:51.159–8:00.120
然後我們實際引入我們的執行個體,所以再次設定我們的 tokenizer、processor 和模型的地方,我們實際上是從我們的執行個體中取得它。
8:00.120–8:06.800
然後我們開始實際處理,所以我們有回呼函數,它將提供我們 post message 的 update 輸出,以及關於我們的 TPS、tokens 和實際輸出的資訊,然後我們有。
8:06.800–8:13.000
我們的 streamer,這裡是我們實際處理資訊的地方,所以我們說的是輸入,我們取得音訊,然後透過我們的 processor 處理它,然後這是我們的轉錄,我們的轉錄基於我們的模型和 generate。
8:13.000–8:21.840
我們說我們傳遞相同的輸入、語言,並且我們實際上是串流事件或串流輸出,所以現在我們有 tokenizer,這給我們顯示在右下角的資訊,關於我們實際使用了多少 tokens,然後我們發送回那部分。
8:21.840–8:29.199
文字作為完成,所以請記住,如果我們查看這些 post messages 是什麼,我們回到這裡,這就是 onmessage received 接收的資訊,所以如果我們向下查看 update,我們看到我們設定。
8:29.199–8:40.320
這裡的 TPS 以及我們的訊息,所以我們的 on message 就在這裡,這是我們發送資訊回來的地方,然後這就是。
8:40.320–8:51.480
我們實際上下傳資訊的地方,所以這裡是我們的 TPS,然後音訊的其餘進度條,我在尋找實際的文字資訊,哦,就在這裡,所以在 ready 時,我們傳遞文字的資訊。
8:51.480–8:59.440
正在更新,這就是它運作的方式,我們基本上是在取用這個資訊,在通過模型之後,然後就在這裡,由模型產生,然後發送回資訊。
8:59.440–9:05.560
所以它正在處理自動區塊,它是音訊區塊,然後轉換它並對此進行轉錄,然後它正在串流,它正在進行 tokenizer 並發送所有這些資訊回來,大家好。
9:05.560–9:12.000
今天到此為止,我們涵蓋了使用 Web GPU 和 Transformers JS 在瀏覽器中進行即時語音辨識,我們能夠深入研究一些程式碼庫,並實際讓他們的示範運作起來,所以很高興能與大家分享。
9:12.000–9:19.519
在右下角顯示我們實際使用了多少 token,然後我們將完成的那部分
9:19.519–9:27.519
文字作為其完成狀態回傳,所以請記住,如果我們查看這些 postMessage 是什麼,我們會回到這裡,並且
9:27.519–9:39.240
這就是正在接收的 onmessage 資訊,所以如果我們向下查看以進行更新,我們會看到我們正在設定
9:39.240–9:50.040
我們這裡的 TPS 以及訊息,所以我們的 onmessage 就在這裡,我們正在將資訊傳送回去,然後這就是
9:50.040–10:02.800
我們實際上將資訊傳遞到這裡的方式,所以這裡就是我們的 TPS,然後進度條的其餘部分在
10:02.800–10:14.399
音訊中,我在尋找關於文字的實際資訊,哦,就在這裡,所以在 ready 時,我們傳遞文字的資訊
10:14.399–10:22.240
正在更新的內容,這就是運作方式,我們基本上是在模型通過之後,從
10:22.240–10:29.920
通過模型然後就在這裡由模型生成然後將該資訊回傳
10:29.920–10:39.639
所以它正在處理自動區塊,也就是音訊區塊,然後轉換它並對此進行轉錄
10:39.639–10:46.160
生成,然後串流傳輸,進行 tokenizer 並將所有這些資訊傳送回去,各位好
10:46.160–10:57.040
今天我們就講到這裡,我們介紹了如何在瀏覽器中使用 Web GPU 和 Transformers JS 進行即時語音辨識,我們能夠深入
10:57.040–11:03.000
深入這個倉庫,實際啟動他們的示範,然後,快樂地探索技術
0:00.480–0:09.280
hey everyone welcome to nning IO I'm JDand today we're going to be looking atreal time in browser speech recognition
嗨,大家好,歡迎來到 Nning IO,我是 JD,今天我們將探討在瀏覽器中即時進行語音辨識。
0:09.280–0:19.720
using web GPU and Transformer JS toactually use speech in the browser sowith that let's go ahead and getstarted all right the first thing that
使用 Web GPU 和 Transformer JS 來實際在瀏覽器中使用語音,那麼讓我們開始吧。首先,
0:19.720–0:26.160
we're going to do everyone is we'regoing to go to this hugging face spaceand basically what we're going to do is
我們要做的第一件事是前往這個 Hugging Face 空間,基本上我們要做的就是
0:26.160–0:36.520
look at this demo for the whisper webGPO uh it's real time in browserecognition it's using the whisper basewhich is a 73 million parameter speech
查看這個 Whisper WebGPU 的示範,它是瀏覽器中的即時辨識,使用的是 Whisper Base,這是一個擁有 7300 萬參數的語音
0:36.520–0:45.000
recognition mod model and using onx andTransformer JS so you can see that theaudio audio visualizer is already
辨識模型,並使用 ONNX 和 Transformer JS,所以你可以看到音訊視覺化器已經
0:45.000–0:53.960
picking up my voice from the microphoneand uh able to do some kind of uh visualwhat we're going to do is actually load
從麥克風捕捉到我的聲音,並且能夠進行某種視覺呈現,我們將實際載入
0:53.960–1:04.159
this model and then we should be able tosee real time uh transcription but whatwe want to showis also that if you go and look at your
這個模型,然後我們應該能夠看到實時的轉錄,但我們想展示的是,如果你去查看你的
1:04.159–1:11.920
network uh right now I have I'm on thiswasm tab and we want to pay attention toboth Fetch and wasm so we're going to go
網路,嗯,現在我在這個 WASM 標籤頁,我們要注意 Fetch 和 WASM,所以我們將前往
1:11.920–1:22.680
ahead and look at the model and you cansee it pulled it in really quickly uhcould be uh because it's cached but uh
查看模型,你可以看到它非常快速地載入,嗯,可能是因為它被快取了,但嗯
1:22.680–1:30.079
this was incredibly fast and it'salready doing the the transcription inreal time you can see that it's trying
這非常快速,它已經在即時進行轉錄,你可以看到它正在嘗試
1:30.079–1:38.560
addpunctuation and uh the token count downhere if we go over to the wasm tab thisall that was loaded it's going
添加標點符號,嗯,以及這裡的計數器,如果我們切換到 WASM 標籤頁,所有這些都已載入,它將
1:38.560–1:48.040
through a worker to establish this andthe size was 4 megabytes so again thiscrazy fast for doing real time uh
透過一個 worker 來建立這個,大小為 4 MB,所以再次強調,這對於在瀏覽器中進行即時轉錄來說非常快速,超級
1:48.040–1:56.200
transcription in the browser superhelpful if you were trying to do uh likechat based systems where you actually
在瀏覽器中進行轉錄非常有用,如果你試圖建立基於聊天的系統,而這些系統實際上
1:56.200–2:07.439
wanted to have voice in with your chatas without having to go out to open AIor some otherum closed Source or even open source
希望將語音整合到你的聊天中,而不需要去呼叫 Open AI 或其他某些
2:07.439–2:14.560
model that uh requires a backend callright again we didn't fetch anythingfrom our back end this was just loaded
閉源或甚至開源的模型,這些模型需要後端呼叫,再次強調,我們沒有從後端獲取任何東西,這只是透過
2:14.560–2:22.680
through the browser so now what we'regoing to do is we're going to take thisand we're going to actually look at the
透過瀏覽器進行,那麼現在我們要做的就是,我們將採取這個方法,並實際查看
2:22.680–2:34.400
repo and and dig into the code so if youcome over here to Transformers Jsthe thing you want to note is you wanto be on uh the
儲存庫拿過來,並深入研究程式碼,所以如果你來到這裡的 Transformer JS,你要注意的是,你要在
2:34.400–2:42.680
V3 Branch this is the the new Branchit's still experimental but it's goingto be the next version of Transformer JS
V3 分支上,這是新的分支,它仍然是實驗性的,但它將是 Transformer JS 的下一個版本
2:42.680–2:46.920
a lot of great examples we've beentrying to go through some of them itfeels like every day they're coming out
有很多很棒的範例,我們一直在嘗試瀏覽其中一些,感覺他們每天都在推出
2:46.920–2:56.959
with a new demo a new model that they'reable to implement um definitely reallycool stuff so if we look at this example
新的示範,新的模型,他們能夠實現,嗯,絕對非常酷的東西,所以如果我們查看這個範例
2:56.959–3:04.239
so we go into Transformer JS examplesand Whisper then we're able to actuallyD dive into this code so what we're
所以我們進入 Transformer JS 範例和 Whisper,然後我們能夠實際深入這個程式碼,所以我們要做的就是將這個
3:04.239–3:08.959
going to do is we're just going to pullthis down get this running on our localmachine and then we'll start digging
下載下來,在我們的本機機器上運行它,然後我們開始深入研究
3:08.959–3:20.519
into the code so I'm going to use cursorI'm already I already have it pulledown but you can do uh get clone andthen come over
程式碼,所以我將使用 Cursor,我已經將它拉下來了,但你可以執行 git clone,然後來到
3:20.519–3:34.640
here and just dothis uh we are so I'm in the root sowhat we need to do is go toexamples and then we're going to do web
這裡,只是執行這個,嗯,我在根目錄,所以我們需要做的是前往 examples,然後我們將執行 web
3:34.640–3:49.680
GPU and go towhisper and we'll do an npminstall and then we'll go ahead and doan npm runDev and what we're going to do is we
GPU 並前往 whisper,我們將執行 npm install,然後我們將執行 npm run dev,而我們要做的就是
3:49.680–4:00.079
have our Local Host here so we can gethis up and running we'll watch reallyquickly if we can gethis uh loaded again super quick you saw
在這裡有我們的本機主機,所以我們可以啟動它,我們將非常快速地查看我們是否能再次載入它,超級快,你看到了
4:00.079–4:06.400
how quickly the the load time was forthat again some of it sometimes it'scashed and the first one's going to be
載入時間有多快,再次強調,其中一些有時會被快取,而第一次載入會
4:06.400–4:20.280
slower but still reallyimpressive so if we look at some of thecore files in here we have our app whichis the main main file and what we're
較慢,但仍然非常令人印象深刻,所以如果我們查看這裡的一些核心檔案,我們有 app,這是主要的檔案,而我們要
4:20.280–4:27.680
going to be looking at is how we'reactually pulling in this worker so thisworker. JS is where we're actually going
查看的是我們如何實際載入這個 worker,所以這個 worker.js 是我們實際上要
4:27.680–4:34.160
to do our Logic for Transformer Js we'repulling in the model we're actuallysending messages back and forth where
執行 Transformer JS 邏輯的地方,我們正在載入模型,我們實際上正在發送訊息來回傳遞,其中
4:34.160–4:44.199
you can see right here that as messagesare coming being received we're actuallygoing to be looking for the type of
你可以看到這裡當訊息被接收時,我們實際上會去尋找事件的類型
4:44.199–4:58.479
event that is being pass and then sendthat uh data as wellso you can see most of this is for likeloading there's uh some update which is
正在傳遞的事件類型,然後發送該資料,所以你可以看到大部分這都是為了載入,有一些更新,這是
4:58.479–5:12.520
where you're updating the textwe're actually going to look and seewhere this is uh is working so if wecontinue down and we are looking at the
你更新文字的地方,我們實際上將查看並查看這是在哪裡運作,所以如果我們繼續向下查看,我們正在查看
5:12.520–5:19.639
recorder this is all the informationabout starting and stopping therecording and then what's Happening Here
recorder,這是關於開始和停止錄音的所有資訊,然後這裡發生了什麼
5:19.639–5:31.479
is we are actually looking at how thisinformation is being sent with this codeso righthere it's saying as the recording is
是我們實際上正在查看這段程式碼如何發送這些資訊,所以在這裡,它說當錄音
5:31.479–5:41.960
coming in we're going to take a blob andchunk it and so then we're going to makea file reader and read those and then
進來時,我們將取得一個 blob 並將其分塊,然後我們將建立一個檔案讀取器並讀取這些,然後
5:41.960–5:57.400
send that on when the file is beingread get that bit information that'sdecoded slice it and then send thoseslices over to our worker so we're
在讀取檔案時發送這些,取得該位元資訊,解碼它,分割它,然後將這些分割部分發送給我們的 worker,所以我們
5:57.400–6:06.039
posting the message to generate ourtranscription on the Fly then this isjust our uh our HTML that we're going to
發送訊息以即時生成我們的轉錄,然後這只是我們將要
6:06.039–6:15.599
be pullingin so what we'll do is we'll jump overto the worker and then we'll take a lookat how this is actually functioning real
載入的 HTML,所以我們將跳轉到 worker,然後我們將查看這實際上是如何即時運作
6:15.599–6:21.319
quick everyone if you haven't alreadyplease remember to like And subscribe ithelps more than you know if you have any
的,大家,如果你還沒有,請記得按讚和訂閱,這比你知道的更有帮助,如果你有任何
6:21.319–6:28.120
questions please leave them in thecomments and with that let's get back toit all right so now that we're in our
請在留言區留下你的問題,接下來讓我們回到正題,好的,現在我們已經進入我們的
6:28.120–6:36.960
worker file we're going to startlooking at how this actually functionsfirst thing is we're loading inTransformers we're going to pull in our
現在我們進入了 worker 檔案,我們將開始查看它實際上的運作方式。第一件事是載入 Transformers,我們將引入 AutoTokenizer、AutoProcessor,以及 whisper 和 text streamer,還有 full。
6:36.960–6:49.000
Autokenizer our Auto processor and then uhwhisper and text stream as well as fullso if we look at what we're first doing
如果我們查看首先執行的動作,我們有一個類別,這是我們的 Pipeline,然後我們實際上使用我們的執行個體,在這裡取得我們的模型。
6:49.000–6:55.280
we have this class which is our Pipelineand then we're actually using ourinstance where we're getting our model
所以我們說這是我們的模型 ID,我們有 tokenizer 和 processor,我們實際上是根據我們的 ID 來取得模型。
6:55.280–7:03.240
so we're saying this is our model ID wehave our tokenizer our processor we'reactually getting the model based on our
在這個階段,我們告訴它 dtype 是什麼,然後特別使用 device webGPU,一旦這些都處理完成。
7:03.240–7:14.280
ID at this point uh we're telling itwhat our dtype is and then specificallywe're using device webGPU and once all of these have processed
我們的 git 執行個體就建立了。如果我們滾動到底部,我們可以大致查看一些載入函數,所以你可以看到這裡有 load,這發生在我們實際發送訊息回來以查看進度條等事項的地方。
7:14.280–7:24.160
uh then our git instance has beenestablished if we scroll down to thebottom we can kind of look at like someof the loader functions so you can see
我們根據我們的訊息建立了一些事件,然後一旦瀏覽器或模型實際載入。
7:24.160–7:32.840
here there's the load this happens likewhere we're actually posting backmessages to actually see see theprogress bar things like that we're
這裡有載入,這發生在我們實際回傳訊息以查看進度條等內容時,我們
7:32.840–7:42.639
stablishing some events based on ourmessage and then once the the browser uhor once the model is actually loaded
並處理語言,然後實際處理它,所以我們首先要做的是說,如果處理返回。
7:42.639–7:51.159
we're going to be looking for thisgenerate function this function is whatreally is going to be taking the audio
如果它不是處理中,則繼續將處理狀態設為 True,維持狀態,我們實際上要發送訊息回來,表示執行緒正在啟動,所以我們將 start 設為狀態。
7:51.159–8:00.120
and taking the language and thenactually processing it so the firsthing we'll be doing is saying is if ifprocessing return
然後我們實際引入我們的執行個體,所以再次設定我們的 tokenizer、processor 和模型的地方,我們實際上是從我們的執行個體中取得它。
8:00.120–8:06.800
if it is not processing then go aheadand set that processing to Truemaintaining State we're actually going
然後我們開始實際處理,所以我們有回呼函數,它將提供我們 post message 的 update 輸出,以及關於我們的 TPS、tokens 和實際輸出的資訊,然後我們有。
8:06.800–8:13.000
to send a message back to say that we'retrans that the thread is starting sowe're saying start as our status and
我們的 streamer,這裡是我們實際處理資訊的地方,所以我們說的是輸入,我們取得音訊,然後透過我們的 processor 處理它,然後這是我們的轉錄,我們的轉錄基於我們的模型和 generate。
8:13.000–8:21.840
then we're actually pulling in ourinstance so again where we set ourtokenizer and our processor and modelwe're actually pulling that from our um
我們說我們傳遞相同的輸入、語言,並且我們實際上是串流事件或串流輸出,所以現在我們有 tokenizer,這給我們顯示在右下角的資訊,關於我們實際使用了多少 tokens,然後我們發送回那部分。
8:21.840–8:29.199
instance and we're starting to actuallyprocess so we have our call backfunction which is going to give us the
文字作為完成,所以請記住,如果我們查看這些 post messages 是什麼,我們回到這裡,這就是 onmessage received 接收的資訊,所以如果我們向下查看 update,我們看到我們設定。
8:29.199–8:40.320
output of our post message of update andinformation about our TPS our tokens andour actual output and then we we have
這裡的 TPS 以及我們的訊息,所以我們的 on message 就在這裡,這是我們發送資訊回來的地方,然後這就是。
8:40.320–8:51.480
our streamer and we this is where we'reactuallyprocessing our information so what we'resaying is our input we're taking our AO
我們實際上下傳資訊的地方,所以這裡是我們的 TPS,然後音訊的其餘進度條,我在尋找實際的文字資訊,哦,就在這裡,所以在 ready 時,我們傳遞文字的資訊。
8:51.480–8:59.440
audio and we're uh putting it throughour processor we then this is ourtranscription our transcription BAS
正在更新,這就是它運作的方式,我們基本上是在取用這個資訊,在通過模型之後,然後就在這裡,由模型產生,然後發送回資訊。
8:59.440–9:05.560
based on our model and our generatewe're saying we're passing our sameinputs our language and we're actually
所以它正在處理自動區塊,它是音訊區塊,然後轉換它並對此進行轉錄,然後它正在串流,它正在進行 tokenizer 並發送所有這些資訊回來,大家好。
9:05.560–9:12.000
streaming the events or streaming theoutput so now we have our tokenizer thisgives us the information that's
今天到此為止,我們涵蓋了使用 Web GPU 和 Transformers JS 在瀏覽器中進行即時語音辨識,我們能夠深入研究一些程式碼庫,並實際讓他們的示範運作起來,所以很高興能與大家分享。
9:12.000–9:19.519
displayed in the bottom right of howmany tokens we're actually using andthen we're posting back that chunk of
在右下角顯示我們實際使用了多少 token,然後我們將完成的那部分
9:19.519–9:27.519
text as it is complete and so rememberif we are looking at what these postmessages are we're coming back here and
文字作為其完成狀態回傳,所以請記住,如果我們查看這些 postMessage 是什麼,我們會回到這裡,並且
9:27.519–9:39.240
that is the information that is being onmessage received so if we look downtoupdate we're seeing that we're setting
這就是正在接收的 onmessage 資訊,所以如果我們向下查看以進行更新,我們會看到我們正在設定
9:39.240–9:50.040
our TPS here as well as uh our messageso our on message right here this iswhere we're being sending theinformation back and then that's how
我們這裡的 TPS 以及訊息,所以我們的 onmessage 就在這裡,我們正在將資訊傳送回去,然後這就是
9:50.040–10:02.800
e're actually passing information downhere so this is where ourTPS is and then uhthe this the rest of the progress bar in
我們實際上將資訊傳遞到這裡的方式,所以這裡就是我們的 TPS,然後進度條的其餘部分在
10:02.800–10:14.399
the audio I'm looking fortheactual uh information around the text ohit's right here so on ready we'repassing the information of the text
音訊中,我在尋找關於文字的實際資訊,哦,就在這裡,所以在 ready 時,我們傳遞文字的資訊
10:14.399–10:22.240
hat's beingupdated and that's how this works is webasically are taking this informationfrom after after it passes passes
正在更新的內容,這就是運作方式,我們基本上是在模型通過之後,從
10:22.240–10:29.920
through the model and then right here sobeing generated by the model and thenposting that information back
通過模型然後就在這裡由模型生成然後將該資訊回傳
10:29.920–10:39.639
so it's processing the auto chunk it isaudio chunk and it's uh then convertingthat and doing a transcription on this
所以它正在處理自動區塊,也就是音訊區塊,然後轉換它並對此進行轉錄
10:39.639–10:46.160
generation then it's streaming it'sdoing the tokenizer and posting all thatinformation back all right everyone
生成,然後串流傳輸,進行 tokenizer 並將所有這些資訊傳送回去,各位好
10:46.160–10:57.040
that's it for us today what we coveredwas using real time speech recognitionin the browser with web GPU andTransformers JS we're able to dig
今天我們就講到這裡,我們介紹了如何在瀏覽器中使用 Web GPU 和 Transformers JS 進行即時語音辨識,我們能夠深入
10:57.040–11:03.000
through some of the repo and actuallyget their demo up and running and sowith that happy nerding
深入這個倉庫,實際啟動他們的示範,然後,快樂地探索技術