mirror of
https://github.com/modelscope/FunASR
synced 2025-09-15 14:48:36 +08:00
* add hotword for deploy_tools * Support wfst decoder and contextual biasing (#1039) * Support wfst decoder and contextual biasing * Turn on fstbin compilation --------- Co-authored-by: gongbo.gb <gongbo.gb@alibaba-inc.com> * mv funasr/runtime runtime * Fix crash caused by OOV in hotwords list * funasr infer * funasr infer * funasr infer * funasr infer * funasr infer * fix some bugs about fst hotword; support wfst for websocket server and clients; mv runtime out of funasr; modify relative docs * del onnxruntime/include/gflags * update tensor.h * update run_server.sh * update deploy tools * update deploy tools * update websocket-server * update funasr-wss-server * Remove self loop propagation * Update websocket_protocol_zh.md * Update websocket_protocol_zh.md * update hotword protocol * author zhaomingwork: change hotwords for h5 and java * update hotword protocol * catch exception for json_fst_hws * update hotword on message * update onnx benchmark for ngram&hotword * update docs * update funasr-wss-serve * add NONE for LM_DIR * update docs * update run_server.sh * add whats-new * modify whats-new * update whats-new * update whats-new * Support decoder option for beam searching * update benchmark_onnx_cpp * Support decoder option for websocket * fix bug of CompileHotwordEmbedding * update html client * update docs --------- Co-authored-by: gongbo.gb <35997837+aibulamusi@users.noreply.github.com> Co-authored-by: gongbo.gb <gongbo.gb@alibaba-inc.com> Co-authored-by: 游雁 <zhifu.gzf@alibaba-inc.com>
115 lines
4.0 KiB
C#
115 lines
4.0 KiB
C#
using System.Collections.Specialized;
|
|
using WebSocketSpace;
|
|
|
|
namespace FunASRWSClient_Offline
|
|
{
|
|
/// <summary>
|
|
/// /主程序入口
|
|
/// </summary>
|
|
public class Program
|
|
{
|
|
private static void Main()
|
|
{
|
|
WSClient_Offline m_funasrclient = new WSClient_Offline();
|
|
m_funasrclient.FunASR_Main();
|
|
}
|
|
}
|
|
|
|
public class WSClient_Offline
|
|
{
|
|
public static string host = "0.0.0.0";
|
|
public static string port = "10095";
|
|
public static string hotword = null;
|
|
private static CWebSocketClient m_websocketclient = new CWebSocketClient();
|
|
[STAThread]
|
|
public async void FunASR_Main()
|
|
{
|
|
loadconfig();
|
|
loadhotword();
|
|
//初始化通信连接
|
|
string errorStatus = string.Empty;
|
|
string commstatus = ClientConnTest();
|
|
if (commstatus != "通信连接成功")
|
|
errorStatus = commstatus;
|
|
//程序初始监测异常--报错、退出
|
|
if (errorStatus != string.Empty)
|
|
{
|
|
//报错方式待加
|
|
Environment.Exit(0);
|
|
}
|
|
|
|
//循环输入推理文件
|
|
while (true)
|
|
{
|
|
Console.WriteLine("请输入转录文件路径:");
|
|
string filepath = Console.ReadLine();
|
|
if (filepath != string.Empty && filepath != null)
|
|
{
|
|
await m_websocketclient.ClientSendFileFunc(filepath);
|
|
}
|
|
}
|
|
}
|
|
private void loadconfig()
|
|
{
|
|
string filePath = "config.ini";
|
|
NameValueCollection settings = new NameValueCollection();
|
|
using (StreamReader reader = new StreamReader(filePath))
|
|
{
|
|
string line;
|
|
while ((line = reader.ReadLine()) != null)
|
|
{
|
|
// 忽略空行和注释
|
|
if (string.IsNullOrEmpty(line) || line.StartsWith(";") || line.StartsWith("#"))
|
|
continue;
|
|
// 解析键值对
|
|
int equalsIndex = line.IndexOf('=');
|
|
if (equalsIndex > 0)
|
|
{
|
|
string key = line.Substring(0, equalsIndex).Trim();
|
|
string value = line.Substring(equalsIndex + 1).Trim();
|
|
if (key == "host")
|
|
host = value;
|
|
else if (key == "port")
|
|
port = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
static void loadhotword()
|
|
{
|
|
string filePath = "hotword.txt";
|
|
try
|
|
{
|
|
// 使用 StreamReader 打开文本文件
|
|
using (StreamReader sr = new StreamReader(filePath))
|
|
{
|
|
string line;
|
|
// 逐行读取文件内容
|
|
while ((line = sr.ReadLine()) != null)
|
|
{
|
|
hotword += line;
|
|
hotword += " ";
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("读取文件时发生错误:" + ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
if (hotword.Length > 0 && hotword[hotword.Length - 1] == ' ')
|
|
hotword = hotword.Substring(0,hotword.Length - 1);
|
|
}
|
|
}
|
|
private static string ClientConnTest()
|
|
{
|
|
//WebSocket连接状态监测
|
|
Task<string> websocketstatus = m_websocketclient.ClientConnTest();
|
|
if (websocketstatus != null && websocketstatus.Result.IndexOf("成功") == -1)
|
|
return websocketstatus.Result;
|
|
return "通信连接成功";
|
|
}
|
|
}
|
|
} |