コード例 #1
0
ファイル: MicTest.cs プロジェクト: Mainstayz/PAIPAILE
    public static string request(string url, string base64audio, int length)
    {
        postObj jsonObj = new postObj()
        {
            format  = "wav",
            rate    = 8000,
            channel = 1,
            lan     = "en",
            token   = "24.586bca0b3411d62559ba3daf80bb7fe9.2592000.1463824780.282335-8035270",
            cuid    = "myUnitySpeech",
            len     = length,
            speech  = base64audio
        };

        string strJson = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);

        string strURL = url;

        System.Net.HttpWebRequest request;
        request        = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
        request.Method = "POST";
        // 添加header
        request.Headers.Add("apikey", "eac9995366c00e5d0025e8ee88e85dbf");
        request.ContentType = "application/json";

        byte[] payload;

        payload = System.Text.Encoding.UTF8.GetBytes(strJson);
        request.ContentLength = payload.Length;

        Stream writer = request.GetRequestStream();

        writer.Write(payload, 0, payload.Length);
        writer.Close();
        Debug.Log(payload);
        System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
        System.IO.Stream           s;
        s = response.GetResponseStream();
        string       StrDate  = "";
        string       strValue = "";
        StreamReader Reader   = new StreamReader(s, Encoding.UTF8);

        while ((StrDate = Reader.ReadLine()) != null)
        {
            strValue += StrDate + "\r\n";
        }
        return(strValue);
    }
コード例 #2
0
    public static string request(string url, string base64audio, int length)
    {
        postObj jsonObj = new postObj()
        {
            format  = "wav",
            rate    = 8000,
            channel = 1,
            lan     = "en",
            token   = "你的access_token",
            cuid    = "随便写",
            len     = length,
            speech  = base64audio
        };

        string strJson = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);

        string strURL = url;

        System.Net.HttpWebRequest request;
        request        = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
        request.Method = "POST";
        // 添加header
        request.Headers.Add("apikey", "你的apikey");
        request.ContentType = "application/json";

        byte[] payload;

        payload = System.Text.Encoding.UTF8.GetBytes(strJson);
        request.ContentLength = payload.Length;

        Stream writer = request.GetRequestStream();

        writer.Write(payload, 0, payload.Length);
        writer.Close();
        System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
        System.IO.Stream           s;
        s = response.GetResponseStream();
        string       StrDate  = "";
        string       strValue = "";
        StreamReader Reader   = new StreamReader(s, Encoding.UTF8);

        while ((StrDate = Reader.ReadLine()) != null)
        {
            strValue += StrDate + "\r\n";
        }
        return(strValue);
    }