[PYTHON] [Remote development] Control application (Practice 2)

In Exercise 1 of Previous, the "CPU usage" of a Windows PC was regarded as a sensor value, and "sense" components were created. This time, we will practice the opposite direction of data flow, that is, the components of the "control" system. As in the last time, I don't know what kind of device you have, so I will explain "playing audio files" and "text speech" that do not require any device. That said, with Limotte, both features can be achieved by writing just a few lines of Python code.

Preparation

Creates a function that sounds a chime-like sound effect when the switch is turned on. Let's prepare an "mp3 file" that contains the sound effect. Please refer to the following sites where you can download free sound sources. Sound Effect Lab   Music-Note.jp   DOVA-SYNDROME In this article, we have prepared "Bell.mp3" which sounds like "ping pong!". In addition, in this exercise, we will create a speech function using the voice function of Windows 10. Go to Windows "Settings", then "Time and Language", "Voice Recognition" menu, and use the "Select Voice" drop-down menu and "Voice Preview" button as shown in the screen below. Let's set the audio. 0 音声の選択.png

From creating a new app to adding components

As in Exercise 1, create an app as follows. 1 アプリの新規作成.png 2 アプリの一覧.png

Create mp3 playback function

First of all, when the switch is turned on, a function to play an audio file (mp3) is created at the station. First, create a new component. Set "I / O type" to "On / Off control". 3 mp3の再生を作成.png Next, select the "Layout" tab in the "Usage Page" tab. The default display items for "on / off control" have already been placed. You can switch to your favorite switch by clicking the expression icon as shown below. 4 水平スイッチ.png Now, in order to implement to play mp3 files when this switch is turned on, in the "Programs" tab in the "Configuration" tab, open the menu and select "Add existing file". Add the prepared mp3 file. 5 既存のファイルの追加.png Next, on the "Code" tab, add the following two lines to the control (self, data) function in the "output_control.py" file. To do.   if data['value'] is True:     self._sys.sound_on_station('Bell.mp3') That's it! 6 mp3再生のコード.png

The function control (self, data) is an interface for telling the Python program what you have operated on the usage page. The function sound_on_station (file_name) is an API that allows a Python program to require the Limotte platform to play an audio file on the station's computer. By the way, if you use the function sound_in_browser (file_name), the sound will be played from all browsers connected to the station.

Run to turn the switch on and off

To start the app, press the "Save" button at the top of the screen, select the "Layout" tab in the "Usage Page" tab, and then press the "Start" button of the app. Every time the switch is turned from off to on, the station will play the specified sound effect.

Create text speech function

Next, let's create a speech function. Add another component in the same app. Set "I / O type" to "Text control". 7 テキストのスピーチを作成.png When the "Layout" tab in the "Usage Page" tab is selected, one item is added in the expression format "Display and input text". In the following, the width is widened so that you can enter longer text, but you may implement it by other input methods by clicking the expression format selection icon. 8 テキストの表現形式.png Finally, add the following line to the control (self, data) function of "output_control.py" as the source code.   self._sys.speak_on_station(data['value'], 'ja') 9 スピーチのコード.png The function speak_on_station (text, lang) allows a Python program to send a given text to the Limotte platform in a specified language (eg,'ja' or'en-us') on the station's computer. An API that requires output. By the way, if you use the function speak_in_browser (text, lang), the sound will be output from all browsers connected to the station.

Run and let the station talk

To start the app, press the "Save" button at the top of the screen, select the "Layout" tab in the "Usage Page" tab, and then press the "Start" button of the app. Enter the text you want to speak and the station will output voice. 10 スピーチの実行.png

Summary

In this exercise, we experienced the components of the "control" system. I want to learn that user operations on the usage page are communicated to Python programs by the control (self, data) function. Next time, we will deal with media (video and audio), which is one of the major features of the Limotte platform, and perform "face detection" on the images acquired from the camera.

Recommended Posts

[Remote development] Control application (Practice 2)
[Remote development] Video analysis application (Practice 3)
[Remote development] Voice analysis application (Practice 4)
[Remote development] Let's make it first !! (Practice 1)
Get FortiGate Application Control ID
Web application development with Flask
WEB application development using Django [Django startup]
WEB application development using Django [Application addition]
Web application development memo in python
Application development with Docker + Python + Flask
Application development using Azure Machine Learning