TwitterFacebook

Using Speech with C# and Visual Studio 2013.

This example will show you how to use Speech with C# an Visual Studio 2013 to recognition your words , speak your words from your list and also to command the exit appplication.
Create one empty project from File – New Project.
You have now one Form and you will add 3 buttons and one TextBox.
After that will need to select MultiLine by using right click on the arrow of TextBox.
The next image show you this 3 buttons and TextBox.
Speek C#
You need to activate Speech from Visual Sudio 2013 IDE:
Go to right panel and Add Reference ( use right click and select it – see next image).
Speek C#
Then select Speech and click Apply – see next image:
Speek C#
All buttons will have source code, just double click on buttons and will have the functions for all buttons.
Also If you want to renamed the buttons just search Properties and then Text and rename buttons or Form title.
I used Speak, Start and Stop for buttons.
I used also one if-else with exit word from list, to stop application.
The list will have all words to recognition your words from list.
You need also to have hardware microphone or portable microphone and also you must activate it unde windows.
Now, the source code of your form is this:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Speech.Synthesis;
using System.Speech.Recognition;
using System.Threading;

namespace Speaking
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        SpeechSynthesizer sSynth = new SpeechSynthesizer();
        PromptBuilder pBuikder = new PromptBuilder();
        SpeechRecognitionEngine sRecognize = new SpeechRecognitionEngine();

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            pBuikder.ClearContent();
            pBuikder.AppendText(textBox1.Text);
            sSynth.Speak(pBuikder);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            button2.Enabled = false;
            button3.Enabled = true;
            Choices sList = new Choices();
            sList.Add(new String[]{"hello","hi","who","how","working","you","test","working","exit"});
            Grammar gr = new Grammar(new GrammarBuilder(sList));
            try {
                sRecognize.RequestRecognizerUpdate();
                sRecognize.LoadGrammar(gr);
                sRecognize.SpeechRecognized += sRecognize_SpeakRecognized;
                sRecognize.SetInputToDefaultAudioDevice();
                sRecognize.RecognizeAsync(RecognizeMode.Multiple);
            }
            catch { return; }
        }
        private void sRecognize_SpeakRecognized(object sender, SpeechRecognizedEventArgs e) {
            //MessageBox.Show("Speek " + e.Result.Text.ToString());
            if (e.Result.Text == "exit")
            {
                Application.Exit();
            }
            else {
                textBox1.Text = textBox1.Text + " " + e.Result.Text.ToString();
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            sRecognize.RecognizeAsyncStop();
            button2.Enabled = true;
            button3.Enabled = false;
        }
    }
}

Using F7 Buil Solution and then Start Debugging – F5 you will run the application.

JSON IP and GeoIP REST API from telize website.

According to telize website :
This service offers a REST API allowing to get a visitor IP address and to query location information from any IP address. It outputs JSON-encoded IP geolocation data, and supports both JSON and JSONP.
There is no rate limit of any sort at the moment, and the service is free for everyone to use.

Today I test it with a simple json script.
This is the html file I used to get all infos.


<!doctype html>
<html>
    <head>
    </head>
    <body>
    <script type="application/javascript">
    function getgeoip(json){
        document.write("Geolocation information for IP address : ", json.ip);
        document.write("<br />");
        document.write("Country : ", json.country);
        document.write("<br />");
        document.write("Country_code : ",json.country_code);
        document.write("<br />");
        document.write("Country_code3 : ",json.country_code3);
        document.write("<br />");
        document.write("Continent : ",json.continent_code);
        document.write("<br />");
        document.write("Latitude : ", json.latitude);
        document.write("<br />");
        document.write("Longitude : ", json.longitude);
        document.write("<br />");
        document.write("Region code : ",json.region_code);
        document.write("<br />");
        document.write("Region : ",json.region);
        document.write("<br />");
        document.write("City : ",json.city);
        document.write("<br />");
        document.write("Postal code : ",json.postal_code);
        document.write("<br />");
        document.write("Continent code : ",json.continent_code);
        document.write("<br />");
        document.write("DMA code : ",json.dma_code);
        document.write("<br />");
        document.write("ISP : ",json.isp);
        document.write("<br />");
        document.write("Area code : ",json.area_code);
        document.write("<br />");
        document.write("ASN : ",json.asn);
        document.write("<br />");
        document.write("Timezone : ",json.timezone);
    }
    </script>  

    <script type="application/javascript" src="http://www.telize.com/geoip?callback=getgeoip"></script>
   </body>
</html>

Using Frame Rate with requestAnimationFrame

Today I will show you one simple tutorial about requestAnimationFrame.
According to mozilla development team ths requestAnimationFrame has made to :
The Window.requestAnimationFrame() method tells the browser that you wish to perform an animation and requests that the browser call a specified function to update an animation before the next repaint. The method takes as an argument a callback to be invoked before the repaint.
This allow you to controlling the frame rate by limiting the frame rate.
First you need to make a simple HTML5 file with h1 tag and id named frame_count ( you can use any id name -if you want).

<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
<script>
</script>
<h1 id=”frame_count”></h1>
</body>
</html>
The next step is to customize with CSS into style tab.
I make it with a Arial green font and bold style.
Just add the next source code into style HTML tag.


html, body {
	width: 50%; height: 50%;
}

body {
	background: whiteSmoke;
	font-family: Arial;
}

#frame_count {
	height: 50px;
	width: 50%;
	
	position: absolute;
	top: 50%;
	margin-top: -50px;
	text-align: center;
	
	font-weight: bold;
	color: #00FF00
;}

Now you need to use javascript with requestAnimationFrame.
Let see the source code:

<!DOCTYPE html> 
<html> 
<head>
<style>
html, body {
 width: 50%; height: 50%;
}

body {
 background: whiteSmoke;
 font-family: Arial;
}

#frame_count {
 height: 50px;
 width: 50%;
 
 position: absolute;
 top: 50%;
 margin-top: -50px;
 text-align: center;
 
 font-weight: bold;
 color: #00FF00
;
}
</style>
</head>
<body> 
<script>
window.requestAnimationFrame = function() {
 return window.requestAnimationFrame ||
 window.webkitRequestAnimationFrame ||
 window.mozRequestAnimationFrame ||
 window.msRequestAnimationFrame ||
 window.oRequestAnimationFrame ||
 function(f_timeout) {
 window.setTimeout(f_timeout,1e3/60);
 }
}();

var $ = document.querySelector.bind(document);
var fps = 60;
var now;
var then = Date.now();
var interval = 1000/fps;
var delta;
var counter = 0;
var first = then;

function draw() {

 requestAnimationFrame(draw);
 
 now = Date.now();
 delta = now - then;

 if (delta > interval) {
 
 then = now - (delta % interval);
 var time_el = (then - first)/1000;
 $('#frame_count').innerHTML = ++counter + 'frames / ' + parseInt(time_el) + 'second = ' + parseInt(counter/time_el) + 'frame per second';
 }
}
draw();</script>
<h1 id="frame_count"></h1>
</body> 
</html>

So two functions: first will used the requestAnimationFrame into the windows and draw function will drawing all into browser.
The first function has another function to setTimeout.This creates a function object and executes it immediately bacause I used }());
Most of variable is named to understand how happend.
I also used this document.querySelector.bind to return the first element within the document (using depth-first pre-order traversal of the document’s nodes) and that matches the specified group of selectors.
And the output is this:
requestAnimationFrame_example

Rainmeter – the new conky for Windows OS – part 001.

If you love it conky under Linux OS then for Wiondows OS you can try Rainmeter.
This application let you to customize your desktop with a lot of infos about web and PC.
Rainmeter is a free, open-source application, that enables skins to run on the desktop.
Some skins can interact with other skins and applications using special commands, called bangs and can be changing with short lines of text, called variables.
With some experience with Rainmeter’s code language you can make or changing someelese skins.
As you can see in this image , the application let you to set by GUI most of the skins and also to change it using your text editor. I used notepad , but you can also use any text editor (like sublime or something else).
Rainmeter tutorial 001
Also I set some default skins like network , data , disks and system.
You can have multimple layouts. I used illustro. Any layout can have many skins.
This skins can be loaded and unloaded by the user. In the bottom of this GUI will see one button named: Edit settings. This allow you to edit the file settings of Rainmeter.
Next will show you something about how to use the Rainmeter.ini file.
For example first line ( see the image from the top):

[Rainmeter]
Logging=0
SkinPath=C:\Users\your_user\Documents\Rainmeter\Skins\

told us about logging -if set to 1, the log will be saved to a file, and also thepath to the skins folder.
Easy to do it if you know how to deal with this file. For example if I add the TrayIcon set by 0, you don’t see the Rainmeter trayicon.

[Rainmeter]
Logging=0
TrayIcon=0
SkinPath=C:\Users\your_user\Documents\Rainmeter\Skins\

Now will try to speak about some basic standard” features of this application.
First is meter and that allow you to defines a visual element.
This visual element is displayed in a skin, does not have a value, has a certain position with dimensions.
Let’s make one skin. Thirst you need to create one folder into this path:

C:\Users\catalin\Documents\Rainmeter\Skins\illustro\

Make also a text file named : MySkin001
… and fil with this :

[Rainmeter]
Update=100
[Metadata]
Name=ShowSprites
Author=www.free-tutorials.org
Information=Displays 11 sprites 
Version= 28.9.2014
License=Creative Commons Attribution

[MeasureAnimation]
Measure=CALC
Formula=Counter % 11

[MeterAnimation]
Meter=BITMAP
MeasureName=MeasureAnimation
BitmapImage=MySkin001.png
BitmapFrames=11
BitmapExtend=1

I used this png file ( I also used gimp to set transparency).
The image is not very clean , but you can make some changes.
rainmeter sprites
Clicl left on trayicon and select Manage. Under Skins tab select illustro -> MySkin001 -> MySkin001.ini and press load button to load the skin.
The next video show you how is working.

If you don’t make yourself all of this settings then you can get a lot of skins from customize.org.

Locate your phone with Android Device Manager – Google store.

GooglePlayPhoneLocator
As you can see Google Play can help you to find your phone under google maps.
Just open your account , go to Settings -> Android Device Manager, and will have this options like Ring and Locate Devices ( see the little icon with a circle from top – right of the window).