Upload
isham-mohamed-iqbal
View
1.134
Download
3
Tags:
Embed Size (px)
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
Citation preview
Develop
Windows 8 &
Windows Phoneapps 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
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.
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.
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.
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.
Calculator API
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
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();
Win 8 app using Calculator API
WP 8 app using Calculator API
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
Currency converter app• Using same calculator api with small
modification– http://www.google.com/ig/calculator?
hl=en&q=1usd=?lkr
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
Get a simple app
• http://tiny.cc/MetroCurrencyConverter
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!!");}
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!");
}
Text to speech in Windows 8 apps
• How many of you have used native TTS feature in Win 8 apps?
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.
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=
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 .
Text to speech in Windows 8 apps
• Set MediaElement control in .xaml page
<MediaElement x:Name="medEle" AudioCategory="BackgroundCapableMedia" Height="100" Width="100"/>
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();
}
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.
Text to speech in Windows 8.1 apps
• Set MediaElement control in .xaml page
<MediaElement x:Name="medEle"/>
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(); }
That’s all..
Q - A