Ошибка 400 при преобразовании текста в речь

Я использую 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)

Когда я запускаю приложение, я получаю следующую ошибку:

Ошибка удаленного сервера (400) Неверный запрос

Я попытался выйти в Интернет с помощью своих браузеров (firefox, chrome и IE):

http://api.microsofttranslator.com/v2/Http.svc/Speak?&appId=myappID=speak со мной=ru

И результат:

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

Кто-нибудь знает, как решить эту проблему?

Большое спасибо!


person Juliet    schedule 16.09.2011    source источник
comment
Полный длинный выстрел - вы пытались взять ; из имен параметров в строке запроса?   -  person AndrewC    schedule 16.09.2011
comment
Спасибо!! это решает проблему! правильный код: string uri = api.microsofttranslator.com/v2/Http .svc/Speak?&appId= + appId +&text= + текст + &language= + язык;   -  person Juliet    schedule 16.09.2011
comment
Я поставлю это как ответ, просто для полноты.   -  person AndrewC    schedule 16.09.2011


Ответы (1)


Удалить ; из имен параметров в строке запроса.

person AndrewC    schedule 16.09.2011