C 呼叫訊飛實時語音轉寫

2021-10-24 08:05:55 字數 3658 閱讀 6231

websocket呼叫訊飛介面類:

using iflycalc.entity;

using iflycalc.utils;

using iflycalc.view;

using system;

using system.collections;

using system.text;

using system.text.regularexpressions;

using system.threading;

using system.threading.tasks;

using websocketsharp;

namespace iflycalc.net

public void initwebsocket()

if (apikey == null || apikey.length == 0)

if (ws == null)

beend = false;

if (connectstate == 1)

connectstate = -1;

while (true)

else if (connectstate == 1)

system.diagnostics.debug.writeline("mywebsocket connect");

if (ws == null)

ws.connect();

connectstate = 0;

if (connectstate == -1)

else if (connectstate == 1)

}} catch (exception ex)

}public void sendbytemsg(byte bytemsg)

}public void sendstrmsg(string strmsg)

}public void closewebsocket()

private task onopen()

private task onclose(closeeventargs arg)

private task onmessage(messageeventargs args)}}

}}

}else if (iflyret.code == "0")

else

} catch (exception ex)

string regstr = sb.tostring();

if (regstr.length > 0)

if (beend)

return null;

}private task onerror(erroreventargs e)

}}

stringutil類:

using iflycalc.entity;

using newtonsoft.json;

using system;

using system.io;

using system.text;

namespace iflycalc.utils

}return returnstr;

}/// /// 獲取時間戳

///

///

public static string gettimestamp()

public static rtadata parsertadata(string text)

catch (exception ex)

return null;

}public static iflyret parseiflyret(string text)

catch (exception ex)

return null;

}public static string urlencode(string str)

return (sb.tostring());}}

}

encryptutil類:

using system;

using system.security.cryptography;

using system.text;

namespace iflycalc.utils

console.writeline(str);//202cb962ac59075b964b07152d234b70

return str;

} catch (exception e)

return null;

}#region hmacsha1加密 對二進位制資料轉base64後再返回

/// /// hmacsha1加密

///

/// 要加密的原串

///私鑰

///

public static string hmacsha1text(string text, string key)

;byte databuffer = system.text.encoding.utf8.getbytes(text);

byte hashbytes = hmacsha1.computehash(databuffer);

return convert.tobase64string(hashbytes);

} catch (exception e)

return null;

}#endregion

}}

呼叫mywebsocket的地方

//按照訊飛文件的要求,從儲存的音訊資料中每隔40毫秒讀取1280byte傳送出去

//mywebsocket需要在前面new乙個,並且把頁面物件帶過去,如下

//mywebsocket = new mywebsocket(page);

private void sendaudiodatatosocket()

system.diagnostics.debug.writeline("bytesource length = " + bytesource.count);

sendindex++;

int remainlen = bytesource.count - sendindex * 1280;

if (remainlen >= 0)

mywebsocket.sendbytemsg(bytesource.getrange((sendindex - 1) * 1280, 1280).toarray());

thread.sleep(40);

if (remainlen == 0)

");bytesource.clear();

sendindex = 0;

system.diagnostics.debug.writeline("send audio data over");

}} else

");bytesource.clear();

sendindex = 0;

system.diagnostics.debug.writeline("send audio data over");

} }"bytesource is null, should not send");

} catch (exception ex)

}

如有不合適的地方,還請多多指正,也希望能幫到大家,^_^

訊飛語音轉寫

邏輯 語音上傳 prepare 訊飛 返回乙個task id 音訊分片上傳 upload 訊飛,呼叫多次,直到檔案全部上傳完成 合併音訊merge 訊飛 每三分鐘呼叫getprogress 訊飛 得到結果getresult 訊飛 訊飛官方文件 介面呼叫流程 安裝外掛程式 js md5 和 crypt...

語音轉寫平台 非實時語音分割

1.question1 非實時音訊切割出許多空白音訊 len audio 0 analysis audiosegment.length 14533 audiosegment.get arrays from samples.length 116267 根據audiosegment.arrays長度切割...

php 訊飛語音評測 訊飛聽見 語音識別工具

摘要 上午刷到冬泳怪鴿黃春生 看見 演講,很有感觸,想將語音轉成文字。找了兩款語音識別軟體軟體萬能君和訊飛聽見,比較之下,訊飛聽見效果更好。章節目錄 3 資源獲取方式 言歸正傳,筆者找了兩款語音識別軟體軟體,分別是萬能君 1 和訊飛聽見 2 萬能君獲取方式 3 免費,可免費呼叫5萬次 缺點 訊飛聽見...