错误400将文本转换为语音

本文关键字:语音 转换 文本 错误 | 更新日期: 2023-09-27 18:08:52

我使用bing的api TTS,我从http://msdn.microsoft.com/en-us/library/ff512420.aspx

获得信息

这是代码(来自网站):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Media;
namespace Apigoogleprova
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Speak();
        }
    private static void ProcessWebException(WebException e, string message)
    {
        Console.WriteLine("{0}: {1}", message, e.ToString());
        // Obtain detailed error information
        string strResponse = string.Empty;
        using (HttpWebResponse response = (HttpWebResponse)e.Response)
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader sr = new StreamReader(responseStream, System.Text.Encoding.ASCII))
                {
                    strResponse = sr.ReadToEnd();
                }
            }
        }
        Console.WriteLine("Http status code={0}, error message={1}", e.Status, strResponse);
    }
     public static void Speak()
    {
        string appId = "myappID"; //go to http://msdn.microsoft.com/en-us/library/ff512386.aspx to obtain AppId.
        string text = "speak to me";
        string language = "en";
        string uri = "http://api.microsofttranslator.com/v2/Http.svc/Speak?&appId=" + appId +"&text;=" + text + "&language;=" + language;
        HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);
        //httpWebRequest.Proxy = new WebProxy(""); set your proxy name here if needed
        WebResponse response = null;
        try
        {
            response = httpWebRequest.GetResponse();
            using (Stream stream = response.GetResponseStream())
            {
                using (SoundPlayer player = new SoundPlayer(stream))
                {
                    player.PlaySync();
                }
            }
        }
        catch (WebException e)
        {
            //ProcessWebException(e, "Failed to speak");
            MessageBox.Show("Error"+e);
        }
        finally
        {
            if (response != null)
            {
                response.Close();
                response = null;
            }
        }
    }

}
}

(我把" myappID "改成了微软提供给我的ID)

当我运行应用程序时,我得到以下错误:

远程服务器错误(400)错误请求

我试着用我的浏览器(firefox, chrome和IE)上网:

http://api.microsofttranslator.com/v2/Http.svc/Speak?&appId=myappID&text;=speak to me&language;=en

结果是:

**Argument Exception** 
Method: Speak()
Parameter: text Message: Value cannot be null.
Parameter name: text message
id=3835.V2_Rest.Speak.25BD061A

谁知道怎么解决这个问题?

非常感谢!

错误400将文本转换为语音

删除;从查询字符串中的参数名称。