Skip to content

Open-source speech recognition toolkit for training, inference, streaming ASR, VAD, punctuation, speaker diarization pipelines, and OpenAI-compatible/MCP serving.

add wav format for h5 and java (#875)

zhaomingwork55ee71e89591
diff --git a/funasr/runtime/html5/static/main.js b/funasr/runtime/html5/static/main.js
index f8d3bfd0f..7e3573d19 100644
--- a/funasr/runtime/html5/static/main.js
+++ b/funasr/runtime/html5/static/main.js
@@ -44,6 +44,7 @@ var upfile = document.getElementById('upfile');
var isfilemode=false; // if it is in file mode
+var file_ext="";
var file_data_array; // array to save file data
var totalsend=0;
@@ -81,6 +82,10 @@ upfile.onchange = function () {
for(let i = 0; i < len; i++) {
let fileAudio = new FileReader();
fileAudio.readAsArrayBuffer(this.files[i]);
+ file_ext=this.files[i].name.split('.').pop().toLowerCase();
+ if(file_ext==="wav"){
+ file_ext="pcm";
+ }
fileAudio.onload = function() {
var audioblob= fileAudio.result;
file_data_array=audioblob;
diff --git a/funasr/runtime/html5/static/wsconnecter.js b/funasr/runtime/html5/static/wsconnecter.js
index 2873022f1..4beec83b3 100644
--- a/funasr/runtime/html5/static/wsconnecter.js
+++ b/funasr/runtime/html5/static/wsconnecter.js
@@ -72,7 +72,12 @@ function WebSocketConnectMethod( config ) { //定义socket连接方法类
"is_speaking": true,
"chunk_interval":10,
"mode":getAsrMode(),
+
};
+ if(isfilemode)
+ {
+ request.wav_format=file_ext;
+ }
console.log(request);
speechSokt.send( JSON.stringify(request) );
console.log("连接成功");
diff --git a/funasr/runtime/java/FunasrWsClient.java b/funasr/runtime/java/FunasrWsClient.java
index eba85bba1..43407f3f8 100644
--- a/funasr/runtime/java/FunasrWsClient.java
+++ b/funasr/runtime/java/FunasrWsClient.java
@@ -50,7 +50,8 @@ public class FunasrWsClient extends WebSocketClient {
}
public FunasrWsClient(URI serverURI) {
- super(serverURI);
+
+ super(serverURI);
}
public FunasrWsClient(URI serverUri, Map<String, String> httpHeaders) {
@@ -64,7 +65,7 @@ public class FunasrWsClient extends WebSocketClient {
// send json at first time
public void sendJson(
- String mode, String strChunkSize, int chunkInterval, String wavName, boolean isSpeaking) {
+ String mode, String strChunkSize, int chunkInterval, String wavName, boolean isSpeaking,String suffix) {
try {
JSONObject obj = new JSONObject();
@@ -78,6 +79,10 @@ public class FunasrWsClient extends WebSocketClient {
obj.put("chunk_size", array);
obj.put("chunk_interval", new Integer(chunkInterval));
obj.put("wav_name", wavName);
+ if(suffix.equals("wav")){
+ suffix="pcm";
+ }
+ obj.put("wav_format", suffix);
if (isSpeaking) {
obj.put("is_speaking", new Boolean(true));
} else {
@@ -114,7 +119,9 @@ public class FunasrWsClient extends WebSocketClient {
// function for rec wav file
public void recWav() {
- sendJson(mode, strChunkSize, chunkInterval, wavName, true);
+ String fileName=FunasrWsClient.wavPath;
+ String suffix=fileName.split("\\.")[fileName.split("\\.").length-1];
+ sendJson(mode, strChunkSize, chunkInterval, wavName, true,suffix);
File file = new File(FunasrWsClient.wavPath);
int chunkSize = sendChunkSize;