#WEBWONDERS : Using device tech from your web app
In todays #WEBWONDERS blog, we uncover two new components from the latest TMS WEB Core v1.8.2.0 release that show how easy it is to access device hardware. As a bonus, there is a small free component based on one of these new system functionality components. Speech synthesis To bring your message with an extra touch, you can these days easily take advantage of speech synthesis that is built-in in any modern browser. The browser offers an API for it and a new TMS WEB Core non-visual component makes it extremely easy to use. It is literally not more difficult that dropping the component on the form and call: WebSpeechSynthesis.Speak(‘It cannot be easier to make me speak’); There are some additional settings that let you further customize this. If you do not like the default voice the browser offers, you can change the voice pitch and rate with the WebSpeechSynthesis.Pitch and WebSpeechSynthesis.Rate properties. And there is more, most browsers will offer different voices you can select from. The WebSpeechSynthesis component retrieves the available voices and makes these accessible via the WebSpeechSynthesis.Voices: TStringList property. This holds a descriptor name for the different voices offer and this descriptor name can be set toWebSpeechSynthesis.Voice to select another voice. Of course, you will want to experience this speech synthesis yourself first hand, so head-over to our demo and have fun playing with it or watch a recording Device orientation Most modern smartphones and tables come these days with a built-in device orientation sensor. And the modern browsers running on these devices already offer access to this sensor. So, in the same philosophy where the VCL offers Windows system functionality via components, TMS WEB Core offers browser functionality via easy to use components. The new TWebDeviceOrientation component is extremely simple to use. Drop it on the form, call the WebDeviceConnection.Start method to start retrieving the sensor info and the event OnHeadingChange is triggered whenever the physical orientation of the device changes. It returns in degrees the direction of the device. Now, we have created a small free component that turns the non-visual device orientation sensor component into a visual compass component. You can use this easily from a TMS WEB Core web client application by including the unit WEBLib.Compass in the uses list and create the component: compass := TWebCompass.Create(Self); compass.Parent := Self; compass.Top := 10; compass.Left := 10; compass.OnClick := CompassClick; Here the component is created and from an event handler for clicking the compass, the compass will start to capture the device orientation sensor info: procedure TCompassForm.CompassClick(Sender: TObject); begin if not compass.Started then begin compass.Start; end; end; One important notice: for the device orientation sensor data to be available for your web app, the app needs to be hosted on a HTTPS enabled domain! You can discover this demo from a device with such device orientation sensor here or watch this replay: Free compass component Finally, a small word about the free component to visualize the device orientation info via a compass. This is basically a visual component (so, it descends from TWebCustomControl) that shows a picture of a compass (a default one or a customized one) and internally, a non-visual TWebDeviceOrientation component is created and its OnHeadingChange event is handled by the component. From this event handler, a transform […]
