Develop Windows 8 & Windows Phone apps using crucial Google APIs

29

description

This presentation I have done for Microsoft Champs community meetup in Colombo, Sri Lanka on 13th September 2013. In this presentation I have shown some examples on how to use some non-documented APIs in developing Windows 8 and Windows Phone apps

Transcript of Develop Windows 8 & Windows Phone apps using crucial Google APIs

Page 1: Develop Windows 8 & Windows Phone apps using crucial Google APIs
Page 2: Develop Windows 8 & Windows Phone apps using crucial Google APIs
Page 3: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Develop

Windows 8 &

Windows Phoneapps using crucial

Google APIs

Page 4: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Isham Mohamed Mohamed Iqbal.

Sabaragamuwa University of Sri

Lanka.

http://about.me/

isham_mohamed_iqbal

Feel free to disturb me in

@isham_m_iqbal

Page 5: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Agenda• Google Crucial APIs.• Calculator API.• Currency converter app.• Keyless calculator.• Text to speech in Windows Phone.• Text to speech for Windows 8 and 8.1

apps.

Page 6: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Crucial APIs• Google have documented and

provide access to many APIs– Eg : Maps API, Calendar API, Drive API

• But there are some APIs used by Google for some critical purposes and those APIs are not provided with official Google documentations.

Page 7: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Crucial APIs• Hackers managed to hack those kind of

APIs to get backdoor access for them.• Google gives no-problem notice to use

them.• Might be change in future.• Very interesting and easiest APIs to use.

– Calculator API & Google TTS API.

Page 8: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Calculator API• (1 / sin(30 deg)) - tan(30 radians) = ???• For windows calculator we have to click

“Sin” and “Tan buttons.• Even Bing app for Win 8 and Win 8.1 search

app doesn't have any idea to solve this.• Using Bing or Google to solve this is quite

easier.

Page 9: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Calculator API

Page 10: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Calculator API• Solution is accessing Google Calculator API• http://www.google.com/ig/calculator?

hl=en&q=– Eg : http://www.google.com/ig/calculator?

hl=en&q=24-8

Page 11: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Calculator API• Any one plz try

– http://www.google.com/ig/calculator?hl=en&q=24+8

• You need to encode the URL correctly since '+' is a reserved character.

• So we need to use WebUtility.UrlEncode();

Page 12: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Win 8 app using Calculator API

Page 13: Develop Windows 8 & Windows Phone apps using crucial Google APIs

WP 8 app using Calculator API

Page 14: Develop Windows 8 & Windows Phone apps using crucial Google APIs

WebClient vs HttpClientWebClient HttpClient

Avail able in older ver sion of .NET .NET 4.5 only.

WinRT appli ca tions can not use this Http Client can be used with WinRT

Pro vides progress reporti ng for downloads. No progress reporti ng for downloads.

Sup ports FTP. No sup port for FTP.You need to new up a Web Client to make con cur rent request.

Sin gle Http Client can make con cur rent requests.

• Portable HttpClient for .NET Framework and Windows Phone release on Feb 2013.

• Can be downloaded from https://nuget.org/packages/Microsoft.Net.Http

Page 15: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Currency converter app• Using same calculator api with small

modification– http://www.google.com/ig/calculator?

hl=en&q=1usd=?lkr

Page 16: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Get chart for currency converter app• Google finance API gives the chart for currency

rates change– https://www.google.com/finance/chart?

q=CURRENCY:USDLKR&tkr=1&p=5Y&chst=vkc&chs=1500x250&chsc=1

Page 17: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Get a simple app

• http://tiny.cc/MetroCurrencyConverter

Page 18: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Text to speech in Windows Phone• You all know these basic things

– Use the Windows.Phone.Speech.Synthesis API to generate synthesized speech.

– Enable ID_CAP_SPEECH_RECOGNITION capability in the app manifest.

– Very simple example :

private async void ButtonSpeakMe_Click(object sender, RoutedEventArgs e){ SpeechSynthesizer synth = new SpeechSynthesizer(); await synth.SpeakTextAsync("This presentation is very boring!!");}

Page 19: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Text to speech in Windows Phone• And some advanced things

– Change language with InstalledVoices class.– Change male / female voice with VoiceGender enum.– Very simple example :

SpeechSynthesizer synth;private async void SpeakFrench_Click(object sender, RoutedEventArgs e){

synth = new SpeechSynthesizer();IEnumerable<VoiceInformation> frenchVoices = from voice in InstalledVoices.All where voice.Language == "fr-FR"

select voice; synth.SetVoice(frenchVoices.ElementAt(0)); await synth.SpeakTextAsync("Cette presentation est tres ennuyeux!");

}

Page 20: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Text to speech in Windows 8 apps

• How many of you have used native TTS feature in Win 8 apps?

Page 21: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Text to speech in Windows 8 apps

• Sadly no native TTS feature in Windows 8 & Win RT 1.0.

• Bing translator API is provided but its really big process.– Register you clientID, clientSecter in https://datamarket.azure.com– Then you code must getting access token for login BingTranslator

API– More detailed instructions are in

http://msdn.microsoft.com/en-us/library/dd576287.aspx

• Try Bing Translator API one day and you will know the pain.

Page 22: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Text to speech in Windows 8 apps• Google have a solution for this

problem• Available in– http://translate.google.com/translate_tts?tl=en&q=

Page 23: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Text to speech in Windows 8 apps• How to get sound stream from web

response?• MediaElement control will help us

here.• Declare Background Tesks - > Audio in

app Package.appxmanifest .

Page 24: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Text to speech in Windows 8 apps

• Set MediaElement control in .xaml page

<MediaElement x:Name="medEle" AudioCategory="BackgroundCapableMedia" Height="100" Width="100"/>

Page 25: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Text to speech in Windows 8 apps

• Add this method in .xaml.cs pageprivate void btnPlayClicked(object sender, RoutedEventArgs e)

{

string pathx =

"http://translate.google.com/translate_tts?tl=en&q="+tb1.Text;

medEle.Source = new Uri(pathx, UriKind.RelativeOrAbsolute);

medEle.Play();

}

Page 26: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Text to speech in Windows 8.1 apps• With Visual Studio 2013 prev, Microsoft

is introducing Windows.Media.SpeechSynthesis namespace.

• This feature is only available for Windows 8.1 and Windows RT 2.0 machines.

Page 27: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Text to speech in Windows 8.1 apps

• Set MediaElement control in .xaml page

<MediaElement x:Name="medEle"/>

Page 28: Develop Windows 8 & Windows Phone apps using crucial Google APIs

Text to speech in Windows 8.1 apps

• Add this method in .xaml.cs page

private async void btnSpeak_click(object sender, RoutedEventArgs e) { MediaElement medEle = this.medEle; var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer(); SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync(txtText.Text); medEle.SetSource(stream, stream.ContentType); medEle.Play(); }

Page 29: Develop Windows 8 & Windows Phone apps using crucial Google APIs

That’s all..

Q - A