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
4. Isham Mohamed Mohamed Iqbal.
Sabaragamuwa University of Sri Lanka.
http://about.me/isham_mohamed_iqbal
Feel free to disturb me in @isham_m_iqbal
5. 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.
6. 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.
7. 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.
8. 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.
10. 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
11. 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();
14. WebClient vs HttpClient
WebClient HttpClient
Available in older version of .NET .NET 4.5 only.
WinRT applications cannot use this HttpClient can be used with WinRT
Provides progress reporting for
downloads.
No progress reporting for downloads.
Supports FTP. No support for FTP.
You need to new up a WebClient to make
concurrent request.
Single HttpClient can make concurrent
requests.
• Portable HttpClient for .NET Framework and Windows Phone release on
Feb 2013.
• Can be downloaded from https://nuget.org/packages/Microsoft.Net.Http
15. Currency converter app
• Using same calculator api with small
modification
– http://www.google.com/ig/calculator?hl=en&q=1usd=?lkr
16. Get chart for currency converter app
• Google finance API gives the chart for
currency rates change
– https://www.google.com/finance/chart?q=CURRENCY:USD
LKR&tkr=1&p=5Y&chst=vkc&chs=1500x250&chsc=1
17. Get a simple app
• http://tiny.cc/MetroCurrencyConverter
18. 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!!");
}
19. 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!");
}
20. Text to speech in Windows 8 apps
• How many of you have used native TTS
feature in Win 8 apps?
21. 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.
22. 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=
23. 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 .
24. Text to speech in Windows 8 apps
• Set MediaElement control in .xaml page
<MediaElement x:Name="medEle"
AudioCategory="BackgroundCapableMedia"
Height="100" Width="100"/>
25. Text to speech in Windows 8 apps
• Add this method in .xaml.cs page
private 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();
}
26. 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.
27. Text to speech in Windows 8.1 apps
• Set MediaElement control in .xaml page
<MediaElement x:Name="medEle"/>
28. 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();
}