public void GetTranslate(string lan, TranslateCallback callback) { if (callback == null) { return; } callback(IsLanTranslated(lan) ? _content[lan] : ""); }
public void GetTranslate(string lan, string content, TranslateCallback callback) { if (callback == null) { return; } Console.WriteLine("翻译服务器向Google翻译API发起翻译请求"); callback(GoogleTranslateApi.GetTranslate(lan, content)); }
/// <summary> /// Translate the provided text using the specified model. /// </summary> /// <param name="text">The text to translate.</param> /// <param name="model_id">The ID of the model to use.</param> /// <param name="callback">The callback to receive the translated text.</param> /// <returns>Returns true on success.</returns> public bool GetTranslation(string text, string model_id, TranslateCallback callback) { if (string.IsNullOrEmpty(text)) { throw new ArgumentNullException("text"); } if (string.IsNullOrEmpty(model_id)) { throw new ArgumentNullException("model_id"); } Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters["model_id"] = model_id; parameters["text"] = new string[] { text }; return(GetTranslation(Json.Serialize(parameters), callback)); }
public void GetTranslate(string lan, TranslateCallback callback) { if (callback == null) { return; } if (_chatContent.IsLanTranslated(lan)) { Console.WriteLine("直接从本地获取翻译"); _chatContent.GetTranslate(lan, callback); } else { HttpDelegate.TranslateChat(_chatContent.GetId(), lan, delegate(string result) { Console.WriteLine("从聊天服务器获取翻译"); _chatContent.AddTranslate(lan, result); callback(result); }); } }
/// <summary> /// Translate the provided text using the specified source and target. /// </summary> /// <param name="text">The text to translate.</param> /// <param name="source">The ID of the source language.</param> /// <param name="target">The ID of the target language.</param> /// <param name="callback">The callback to receive the translated text.</param> /// <returns>Returns true on success.</returns> public bool GetTranslation(string text, string source, string target, TranslateCallback callback) { if (string.IsNullOrEmpty(text)) { throw new ArgumentNullException("text"); } if (string.IsNullOrEmpty(source)) { throw new ArgumentNullException("source"); } if (string.IsNullOrEmpty(target)) { throw new ArgumentNullException("target"); } Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters["source"] = source; parameters["target"] = target; parameters["text"] = new string[] { text }; return(GetTranslation(Json.Serialize(parameters), callback)); }
private bool GetTranslation(string json, TranslateCallback callback) { if (callback == null) { throw new ArgumentNullException("callback"); } RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, "/v2/translate"); if (connector == null) { return(false); } TranslateReq req = new TranslateReq(); req.Callback = callback; req.OnResponse = TranslateResponse; req.Send = Encoding.UTF8.GetBytes(json); req.Headers["accept"] = "application/json"; req.Headers["Content-Type"] = "application/json"; return(connector.Send(req)); }
public void GetTranslate(long id, string lan, TranslateCallback callback) { if (callback == null || !_chatContent.ContainsKey(id)) { return; } TranslateData translateData = _chatContent[id]; if (!translateData.IsTranslated(lan)) { Console.WriteLine("聊天服务器未记录当前语言的翻译,向翻译服务器发起请求"); _translateServer.GetTranslate(lan, translateData.OriginContent, delegate(string result) { translateData.AddTranslate(lan, result); callback(result); }); } else { Console.WriteLine("聊天服务器存在已翻译内容,直接向客户端回复"); callback(translateData.GetTranslate(lan)); } }
public static async void translate(string text, int volume, int speed, int voiceType, TranslateCallback cb) { byte[] audioData = null; string err = null; try { TextToVoiceRequest req = new TextToVoiceRequest(); req.Text = text; req.SessionId = Convert.ToString(sessionId++); req.ModelType = 1; req.Volume = volume; req.Speed = speed; req.VoiceType = voiceType; req.Codec = "mp3"; TextToVoiceResponse res = await client.TextToVoice(req); audioData = Convert.FromBase64String(res.Audio); } catch (Exception e) { err = e.Message; } cb?.Invoke(text, audioData, err); }
public static void TranslateChat(long id, string lan, TranslateCallback callback) { ChatServer.GetTranslate(id, lan, callback); }