MCPcopy Index your code
hub / github.com/modelscope/FunASR / recWav

Method recWav

runtime/java/FunasrWsClient.java:150–200  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

148
149 // function for rec wav file
150 public void recWav() {
151 String fileName=FunasrWsClient.wavPath;
152 String suffix=fileName.split("\\.")[fileName.split("\\.").length-1];
153 sendJson(mode, strChunkSize, chunkInterval, wavName, true,suffix);
154 File file = new File(FunasrWsClient.wavPath);
155
156 int chunkSize = sendChunkSize;
157 byte[] bytes = new byte[chunkSize];
158
159 int readSize = 0;
160 try (FileInputStream fis = new FileInputStream(file)) {
161 if (FunasrWsClient.wavPath.endsWith(".wav")) {
162 fis.read(bytes, 0, 44); //skip first 44 wav header
163 }
164 readSize = fis.read(bytes, 0, chunkSize);
165 while (readSize > 0) {
166 // send when it is chunk size
167 if (readSize == chunkSize) {
168 send(bytes); // send buf to server
169
170 } else {
171 // send when at last or not is chunk size
172 byte[] tmpBytes = new byte[readSize];
173 for (int i = 0; i < readSize; i++) {
174 tmpBytes[i] = bytes[i];
175 }
176 send(tmpBytes);
177 }
178 // if not in offline mode, we simulate online stream by sleep
179 if (!mode.equals("offline")) {
180 Thread.sleep(Integer.valueOf(chunkSize / 32));
181 }
182
183 readSize = fis.read(bytes, 0, chunkSize);
184 }
185
186 if (!mode.equals("offline")) {
187 // if not offline, we send eof and wait for 3 seconds to close
188 Thread.sleep(2000);
189 sendEof();
190 Thread.sleep(3000);
191 close();
192 } else {
193 // if offline, just send eof
194 sendEof();
195 }
196
197 } catch (Exception e) {
198 e.printStackTrace();
199 }
200 }
201
202 @Override
203 public void onOpen(ServerHandshake handshakedata) {

Callers 1

runMethod · 0.80

Calls 4

sendJsonMethod · 0.95
sendEofMethod · 0.95
readMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected