XP-YESSSSSSS

Dell's already awesome XPS 15 gets even better in 2017

Surface table meets Windows 10

Yes, we did put Windows 10 on the original Surface table ... and it rocks

Cream o' the crop

Before buying a Microsoft laptop, check out our pick for the absolute best

Simple and secure, just the way I like it

We think Windows 10 Cloud is a great idea, here's why

uber micro

Halo Wars 2 has something for everyone. Here's our full review.

Oldie but goldie

We reviewed Microsoft's decade-old Surface table

Creators Update comin' at ya

These are the coolest new features in the next big Xbox One update (video)

Buyer's guide

The Razer Blade 14 is the best laptop Razer has to offer

Windows 10 app gems

10 terrific Windows 10 apps you should be using

Tower of power

Here's what we think of Dell's XPS Tower Special Edition

Quite a deal

Grab the complete C# coding bootcamp for $41!

Your go-to laptop guide

Introducing our ultimate laptop buyer's guide

Listen here

Attn Android and iPhone users: What you need to know about Windows phone

Old is new?

The original Surface Pro still holds its own in the 2-in-1 world

Xbox Greenlight?

No, internet, Microsoft isn't opening Xbox to all UWP games

Falling in love

HP Envy 34 review: An ultrawide curved all-in-one after my heart

2015 machine in 2017?

Surface 3 still holds its own in 2017

Let Kodi cut your cord

You should be using Kodi for Windows 10

Leader of the pack

HP's Spectre x360 15 just might be the best all-around laptop

New or refurbed?

Is a refurbed Surface right for you?

< >
Welcome to the Windows Central Forums Create Your Account or Ask a Question Answers in 5 minutes - no registration required!
Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By RogueCode
  1. BrilliSoft's Avatar
    Member

    Posts
    12 Posts
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
       #1  
    Hi everyone. Has anyone had any luck with using Google's text to speech on WP7? Why won't this code work? Am I missing something obvious?

    [CODE]using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Microsoft.Phone.Controls;
    using System.IO;


    namespace WCTest
    {
    public partial class MainPage : PhoneApplicationPage
    {
    string searchString = "http://translate.google.com/translate_tts?tl=en&q=hello";

    // Constructor
    public MainPage()
    {
    InitializeComponent();

    WebClient client = new WebClient();

    client.OpenReadCompleted += (s, e) =>
    {
    if (e.Error == null)
    {
    Stream audio = e.Result;
    mediaElement1.SetSource(audio);
    mediaElement1.Play();
    }

    client.OpenReadAsync(new Uri(searchString));
    };

    }
    }
    }[/CODE]
  2. thed's Avatar
    Member

    Posts
    993 Posts
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    #2  
    I don't have any experience with Google Translate so I don't know if I can help, but it might help others if you provide more information. What happens when you run this code? Does it throw any exceptions? Does the response stream have any data in it?
  3. thed's Avatar
    Member

    Posts
    993 Posts
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    #3  
    Also, looking at your code, it looks like your call to client.OpenReadAsync is placed inside the event handling method, so it's never making the call. Try moving that line outside the event handling method.
  4. RogueCode's Avatar
    Retired Moderator

    Posts
    76 Posts
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    #4  
    Google shuts down services all too often to be reliable. I would suggest using an alternative provider.
    Here is a good guide on using Bing: Text to Speech in Windows Phone 7 - CodeProject
    BrilliSoft likes this.
  5. BrilliSoft's Avatar
    Member

    Posts
    12 Posts
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
       #5  
    Thanks for the replies. The saga continues...

    The following code works on some of my colleagues' computers, but not on mine... What could cause that? Please let me know if this works for you and if you think it's necessary to save the file to IsolatedStorage...

    [CODE]namespace PhoneApp1
    {
    public partial class MainPage : PhoneApplicationPage
    {
    // Constructor
    public MainPage()
    {
    InitializeComponent();
    }

    string searchString = "http://translate.google.com/translate_tts?tl=en&q=it+works";

    private void button1_Click(object sender, RoutedEventArgs e)
    {
    WebClient client = new WebClient();

    client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0)" + " (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";

    client.Headers[HttpRequestHeader.Referer] = "http://translate.google.com";

    client.OpenReadCompleted += (s, ex) =>
    {

    if (ex.Error == null)
    {
    using (var store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
    {
    if (store.FileExists("hello3.mp3"))
    {
    store.DeleteFile("hello3.mp3");
    }
    using (var fs = new System.IO.IsolatedStorage.IsolatedStorageFileStream("hello3.mp3", System.IO.FileMode.Create, store))
    {
    byte[] bytesInStream = new byte[ex.Result.Length];
    ex.Result.Read(bytesInStream, 0, (int)bytesInStream.Length);
    fs.Write(bytesInStream, 0, bytesInStream.Length);
    fs.Flush();

    mediaElement1.SetSource(fs);
    }
    }

    mediaElement1.Play();

    }

    };

    client.OpenReadAsync(new Uri(searchString));
    }
    }
    } [/CODE]
  6. BrilliSoft's Avatar
    Member

    Posts
    12 Posts
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
       #6  
    Quote Originally Posted by thed View Post
    I don't have any experience with Google Translate so I don't know if I can help, but it might help others if you provide more information. What happens when you run this code? Does it throw any exceptions? Does the response stream have any data in it?
    I set a breakpoint right after the if statement and it never files, so Google isn't allowing it...
  7. BrilliSoft's Avatar
    Member

    Posts
    12 Posts
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
       #7  
    Quote Originally Posted by thed View Post
    Also, looking at your code, it looks like your call to client.OpenReadAsync is placed inside the event handling method, so it's never making the call. Try moving that line outside the event handling method.
    Thanks, I spotted that and fixed it, but still no luck :-/.
  8. BrilliSoft's Avatar
    Member

    Posts
    12 Posts
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
       #8  
    Quote Originally Posted by RogueCode View Post
    Google shuts down services all too often to be reliable. I would suggest using an alternative provider.
    Here is a good guide on using Bing: Text to Speech in Windows Phone 7 - CodeProject
    I think you may be right. Going to have to go a different route...

Posting Permissions