Explain how to use the SDK.
Requirements
SDK | Requirement |
.NET | .Net Framework 4.5 or later |
Ruby | Ruby version 1.9 or later |
Installed gem | |
Python | Python version 3.2 or later |
Installed pip and wheel |
|
Import packages. (numpy, pycrypto). if you have used python’s version < 3.4, need enum34 package. | |
Java | In progress |
How to Implement
SDK | Implement |
.NET | Download of SDK for .NET: haruzira_sdk_dotnet.zip
Show the solution explorer on the Visual Studio. Add “HzClientTcpCommunication.dll” by “reference” of the solution explorer. using HzClientTcpCommunication; |
Ruby | Install the gem package, enter “gem install haruzira_sdk”.
Insert the following code at the require part of your source file. require “haruzira_sdk”. |
Python | Install the pypi package, enter “pip install haruzira_sdk” or “pip3 install haruzira_sdk”.
Insert the following code at the import part of your source file. import haruzirasdk.hz_client_tcp_communication as hzcomm or from haruzirasdk import hz_client_tcp_communication as hzcomm |
Java | In progress |
Examples for basic programming
Example 1
This is a most small program for sending the text of “Hello Haruzira!”.
As a prerequisite, Server is assumed to operate on the following connection information.
IP: “192.168.1.10”, Port:46000
and not carried out the post-reception processing of asynchronous messages in this example.
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
using HzClientTcpCommunication; ClientTcpCommunication cltTcpComm = new ClientTcpCommunication(); cltTcpComm.ServerPortNo = 46000; #port number of the destination cltTcpComm.ServerIP = "192.168.1.10"; #ip address of the destination cltTcpComm.ReqSendDataText = "Hello Haruzira!"; string timeStamp = await cltTcpComm.sendSpeechDataEx(); if (timeStamp != null) Debug.WriteLine("success. timestamp[{0}]", (object)timeStamp); else Debug.WriteLine("failed to send."); |
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
require "haruzira_sdk" cltTcpComm = ClientTcpCommunication.new cltTcpComm.ServerPortNo = 46000 #port number of the destination cltTcpComm.ServerIP = "192.168.1.10" #ip address of the destination cltTcpComm.ReqSendDataText = "Hello Haruzira!" timeStamp = cltTcpComm.sendSpeechDataEx if(timeStamp != nil) puts("success. timestamp[%s]" % [timeStamp]) else puts("failed to send.") end |
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# coding: utf-8 from haruzirasdk import hz_client_tcp_communication as hzcomm clt_tcp_comm = hzcomm.ClientTcpCommunication() clt_tcp_comm.ServerPortNo = 46000 #port number of the destination clt_tcp_comm.ServerIP = "192.168.1.10" #ip address of the destination clt_tcp_comm.ReqSendDataText = "Hello Haruzira!" timestamp = clt_tcp_comm.sendSpeechDataEx() if(timestamp is not None): print("success. timestamp[{}]".format(timestamp)) else: print("failed to send.") #Need to stop listener thread when before your program complete. clt_tcp_comm.cancelAsynchronousListener() |
Example 2
This is a simple program for that receive ‘Send Speech Recognition Command’ message and return text message data to sender.
As a prerequisite, Server(Haruzira) has been regist that the following command information.
Command name: “Weather Information”
Encryption: not use
As a prerequisite, Client has been work that the following port number for listener.
Also, this sample callback function for receiving ‘Send Speech Recognition Command’ message is a following name.
rcvSendSpeechRecognitionCommand()
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
using System; using System.Windows; using System.Windows.Threading; using HzClientTcpCommunication; namespace RegistedCommand { /// <summary> /// MainWindow.xaml の相互作用ロジック /// </summary> public partial class MainWindow : Window { //create instance ClientTcpCommunication cltTcpComm = new ClientTcpCommunication(); public MainWindow() { InitializeComponent(); //regist callback function. cltTcpComm.evNotifySendSpeechRecognitionCommand += new delegateNotifySendSpeechRecognitionCommand(rcvSendSpeechRecognitionCommand); //Set listener port number and start listener. cltTcpComm.ReceivePort = 46100; cltTcpComm.startAsynchronousListener(); } // Callback funtion private void rcvSendSpeechRecognitionCommand(SpeechRecognitionCommandInfo cmdInfo) { Dispatcher.BeginInvoke(new Action(async () => { //txtNotify is a TextBox control. TxtNotify.Text += string.Format("ip[{0}], port[{1}], command[{2}], time stamp[{3}]", cmdInfo.IpAddr, cmdInfo.Port, cmdInfo.Command, cmdInfo.Timestamp) + "\r\n"; //check received string msg; if (cmdInfo.Command.ToLower() == "weather information") msg = "It's sunny today.\r\nBut, It will probably be rainy tomorrow."; else msg = string.Format("Invalid command name. [{0}]\r\nI can't work your command.", cmdInfo.Command); //send speech data. cltTcpComm.ServerPortNo = cmdInfo.Port; cltTcpComm.ServerIP = cmdInfo.IpAddr; cltTcpComm.ReqSendDataText = msg; await cltTcpComm.sendSpeechDataEx(); }), DispatcherPriority.Send); } } } |
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
require "time" require "haruzira_sdk" #create instance clt_tcp_comm = ClientTcpCommunication.new #variable for terminal event. terminate_flg = false #Callback funtion rcvSendSpeechRecognitionCommand = lambda{|cmd_info| puts("Ip[%s], Port[%d], Command[%s], Timestamp[%s]" % [cmd_info.IpAddr, cmd_info.Port, cmd_info.Command, cmd_info.Timestamp]) #check received command if (cmd_info.Command.casecmp("weather information") == 0) msg = "It's sunny today.\r\nBut, It will probably be rainy tomorrow." else msg = "Invalid command name. [%s]\r\nI can't work your command." % [cmd_info.Command] end #send speech data. clt_tcp_comm.ServerPortNo = cmd_info.Port clt_tcp_comm.ServerIP = cmd_info.IpAddr clt_tcp_comm.ReqSendDataText = msg clt_tcp_comm.sendSpeechDataEx #set terminate flag. terminate_flg = true } #regist callback function. clt_tcp_comm.EvNotifySendSpeechRecognitionCommand = rcvSendSpeechRecognitionCommand #Set listener port number and start listener. clt_tcp_comm.ReceivePort = 46100 clt_tcp_comm.ReqSendDataCompletionNoticeNecessity = HzSpCompletionNoticeNecessity::NoNeed clt_tcp_comm.startAsynchronousListener() #waiting for until a command is received. loop do if(terminate_flg) puts("terminate this process.") break end sleep(1) end |
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# coding: utf-8 import time import threading from haruzirasdk import hz_client_tcp_communication as hzcomm #variable for terminal event. terminate_flg = False #create instance clt_tcp_comm = hzcomm.ClientTcpCommunication() #Callback funtion def rcv_send_speech_recognition_command(cmd_info): print("Ip[{0:s}], Port[{1:d}], Command[{2:s}], Timestamp[{3:s}]".format(cmd_info.ip_addr, cmd_info.port, cmd_info.command, cmd_info.timestamp)) global terminate_flg #check received command if(cmd_info.command.lower() == "weather information"): msg = "It's sunny today.\r\nBut, It will probably be rainy tomorrow." else: msg = "Invalid command name. [{0:s}]\r\nI can't work your command.".format(cmd_info.command) #send speech data clt_tcp_comm.ServerIP = cmd_info.ip_addr clt_tcp_comm.ServerPortNo = cmd_info.port clt_tcp_comm.ReqSendDataText = msg clt_tcp_comm.sendSpeechDataEx() #set terminate flag. terminate_flg = True #regist callback function. clt_tcp_comm.evNotifySendSpeechRecognitionCommand = rcv_send_speech_recognition_command #set listener port number and start listener. clt_tcp_comm.ReceivePort = 46300 #set as unnecessary message the 'speech completion notice'. clt_tcp_comm.ReqSendDataCompletionNoticeNecessity = hzcomm.HzSpCompletionNoticeNecessity.NoNeed.value #start listener for asynchronous message. clt_tcp_comm.startAsynchronousListener() #waiting for until a command is received. while True: if(terminate_flg): print("terminate this process.") break time.sleep(1) #Need to stop listener thread when before your program complete. clt_tcp_comm.cancelAsynchronousListener() |
if you need more information about SDK, make reference to the sample programs.