0

我正在使用 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”更改为 Microsoft 提供给我的 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

有谁知道如何解决这个问题?

非常感谢!

4

1 回答 1

1

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

于 2011-09-16T11:01:05.503 回答