Вопрос

I’m using bing’s api TTS, I get the information from: http://msdn.microsoft.com/en-us/library/ff512420.aspx

This is the code (from the webside):

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;
            }
        }
    }



}
}

(I changed “myappID” with the ID that has provided me Microsoft)

When I run the app I get the following error:

Remote Server Error (400) Bad Request

I tried to go to the web with my browsers (firefox, chrome and IE):

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

And the result is:

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

Anyone know how to solve this problem?

Thank you very much!

Это было полезно?

Решение

Remove the ; from the parameter names in the query string.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top