@@ -7,16 +7,16 @@ import { MyWorker } from './Workers/MyWorker.js';
77// 添加页面元素
88$ ( 'body' ) . append ( `
99 <div>
10- <input type="file" id="audio_input" accept="audio/* " capture="microphone"/>
10+ <input type="file" id="audio_input" accept=".wav, .mp3, .flac, .aac, .m4a, .opus, .ogg " capture="microphone"/>
1111 <button id="record_btn" >Record</button>
1212 </div>`
1313) ; const audio_input = document . querySelector ( '#audio_input' ) ; const record_btn = document . querySelector ( '#record_btn' ) ;
1414$ ( 'body' ) . append ( `<div id='audios'></div>` ) ; const audios_div = document . querySelector ( '#audios' ) ;
1515
16- const waveDrawer = new WaveDrawer ( 'audioWave' , 1000 , 125 ) ;
17- const stftDrawer = new StftDrawer ( 'audioStft' , 1000 , null ) ;
18-
16+ const waveDrawer = new WaveDrawer ( 'audioWave' ) ;
17+ const stftDrawer = new StftDrawer ( 'audioStft' ) ;
1918$ ( 'body' ) . append ( `<button id='switch_btn'></button>` ) ; const switch_btn = document . querySelector ( '#switch_btn' ) ;
19+ $ ( 'body' ) . append ( `<button id='open_model_btn'></button>` ) ; const open_model_btn = document . querySelector ( '#open_model_btn' ) ;
2020// 元素添加完毕
2121
2222// 设置页面元素事件
@@ -60,9 +60,8 @@ record_btn.onclick = async (e) => {
6060 } ;
6161} ;
6262
63- switch_btn . disabled = true ;
64- switch_btn . textContent = "Loading..."
65- switch_btn . onclick = async function ( e ) {
63+ switch_btn . textContent = "Start" ;
64+ switch_btn . onclick = function ( e ) {
6665 if ( audioProcesser . isRunning ( ) ) {
6766 audioProcesser . stop ( ) ;
6867 e . target . textContent = "Start" ;
@@ -73,6 +72,19 @@ switch_btn.onclick = async function (e) {
7372
7473} ;
7574
75+ let is_open_model = false ;
76+ open_model_btn . disabled = true ;
77+ open_model_btn . textContent = "ModelLoading..." ;
78+ open_model_btn . onclick = function ( e ) {
79+ if ( is_open_model ) {
80+ is_open_model = false ;
81+ e . target . textContent = "OpenModel" ;
82+ } else {
83+ is_open_model = true ;
84+ e . target . textContent = "StopModel" ;
85+ } ;
86+ } ;
87+
7688
7789//
7890
@@ -95,8 +107,8 @@ myWorker.reciveData('Event', (content) => {
95107 break ;
96108 case 'inited' :
97109 console . log ( 'myWorkerScript Inited!' ) ;
98- switch_btn . textContent = "Start " ;
99- switch_btn . disabled = false ;
110+ open_model_btn . textContent = "OpenModel " ;
111+ open_model_btn . disabled = false ;
100112 break ;
101113 default :
102114 console . error ( `[MainThread]收到未知Event:${ content } ` ) ;
@@ -109,7 +121,7 @@ const audioProcesser = new AudioFlowProcesser(
109121 'sound' ,
110122 sampleRate ,
111123 undefined ,
112- 256 ,
124+ 512 ,
113125 1 ,
114126 ( audioData_Clip ) => {
115127 audioContainer . updateAudioDataClip ( audioData_Clip ) ;
@@ -120,21 +132,23 @@ const audioProcesser = new AudioFlowProcesser(
120132 audioContainer . updateStftDataClip ( stftData_Clip ) ;
121133 stftDrawer . set_data ( audioContainer . getStftData ( ) ) ;
122134
123- myWorker . sendData (
124- 'stftData' ,
125- {
126- sampleRate : stftData_Clip . sampleRate ,
127- fft_n : stftData_Clip . fft_n ,
128- hop_n : stftData_Clip . hop_n ,
129- stft : {
130- stftMartrixArrayBuffer : stftData_Clip . stft . _arrayBuffer ,
131- stftMartrixHeight : stftData_Clip . stft . height ,
132- stftMartrixWidth : stftData_Clip . stft . width ,
135+ if ( is_open_model ) {
136+ myWorker . sendData (
137+ 'stftData' ,
138+ {
139+ sampleRate : stftData_Clip . sampleRate ,
140+ fft_n : stftData_Clip . fft_n ,
141+ hop_n : stftData_Clip . hop_n ,
142+ stft : {
143+ stftMartrixArrayBuffer : stftData_Clip . stft . _arrayBuffer ,
144+ stftMartrixHeight : stftData_Clip . stft . height ,
145+ stftMartrixWidth : stftData_Clip . stft . width ,
146+ } ,
147+ audioTime : stftData_Clip . audioTime ,
133148 } ,
134- audioTime : stftData_Clip . audioTime ,
135- } ,
136- [ stftData_Clip . stft . _arrayBuffer ]
137- ) ;
149+ [ stftData_Clip . stft . _arrayBuffer ]
150+ ) ;
151+ } ;
138152 } ,
139153 null ,
140154) ;
0 commit comments