Skip to main content

Flutter Tutorial: Create Speech to Text

 On this tutorial, we will learn to create a speech to text apps using Flutter. Just like other TTS, spech to text a very helpful and unique feature that can you add to your apps.

Step 1. Add dependencies
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2

and import this packages

import 'package:speech_to_text/speech_recognition_result.dart';
import 'package:speech_to_text/speech_to_text.dart';
Step 2. In your main.dart

Create a speech to text variables.

SpeechToText _speechToText = SpeechToText();
bool _speechEnabled = false;
String _lastWords = '';
Step 3. Initialize the function
  void initState() {

  /// This has to happen only once per app
  void _initSpeech() async {
    _speechEnabled = await _speechToText.initialize();
    setState(() {});
Step 4. Add the listening function
void _startListening() async {
    await _speechToText.listen(onResult: _onSpeechResult);
    setState(() {});  // so that the changes are visible on screen
void _onSpeechResult(SpeechRecognitionResult result) {
    setState(() {
      _lastWords = result.recognizedWords;   // result variable stores all the data.

 /// Manually stop the active speech recognition session
  /// Note that there are also timeouts that each platform enforces
  /// and the SpeechToText plugin supports setting timeouts on the
  /// listen method.
  void _stopListening() async {
    await _speechToText.stop();
    setState(() {});

Step 5. Create the UI

Add to your desired frames:

 child: Container(
 padding: EdgeInsets.all(16),
 child: Text(
 // If listening is active show the recognized words
     ? '$_lastWords'
                           : _speechEnabled
                          ? 'Tap the microphone to start listening...'
                          : 'Speech not available',

Add the floating button

floatingActionButton: FloatingActionButton(
// If not yet listening for speech start, otherwise stop
_speechToText.isNotListening ? _startListening : _stopListening,
tooltip: 'Listen',
child: Icon(_speechToText.isNotListening ? Icons.mic_off : Icons.mic),
I hope you can implement this tutorial in your apps.


Popular posts from this blog

Cara Disable Antimalware Service Executable di Windows 10

Disadari atau tidak, Windows 10 (dan juga windows-windows lainnya) hadir dengan banyak sekali aplikasi bloatware (aplikasi yang tidak perlu-perlu amat dimiliki oleh end user). Contohnya, adalah aplikasi yang seharusnya sudah tergantikan fungsinya oleh antivirus, seperti Antimalware Service Executable . Aplikasi ini dicurigai membuat Windows 10 mengalami inefisiensi memori/RAM, memakan resource yang tinggi, dengan Load yang tinggi (tanpa limit terkadang). Nah, berikut adalah cara men-disable nya: Tekan tombol Windows + I untuk membuka apliaksi Windows Setting. Pilih icon menu Update and Security Pilih lagi menu disamping kiri Windows Security Pada jendela baru yang muncul, ada pilihan Virus & Threat protection Klik ini Lalu matikan proses Real-time protection tersebut. Dengan Regedit. Buka dialog regedit, Windows + R dan ketik ‘regedit’ Cari Folder regedit ini HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender Buat sebuah DWORD baru dengan klik kanan

Setup Debian 11 Official Repository In sources.list (/etc/apt/sources.list)

When you install Debian 11 using a DVD, the OS installer sets the DVD as the source for getting packages for your system if you didn't choose to scan for network mirrors. Due to this reason, the system would ask you to insert a DVD if the disc is not present in the DVD drive when you try to install any software.  Also, the packages on DVD may not be the latest release.  So, we need to get the packages from the Internet. Media change: please insert the disc labeled 'Debian GNU/Linux 11.0.0 _Bullseye_ - Official amd64 DVD Binary-1 20210814-10:04' in the drive '/media/cdrom/' and press [Enter] The /etc/apt/sources.list file with DVD as a source would look something like below. # deb cdrom:[Debian GNU/Linux 11.0.0 _Bullseye_ - Official amd64 DVD Binary-1 20210814-10:04]/ bullseye contrib main deb cdrom:[Debian GNU/Linux 11.0.0 _Bullseye_ - Official amd64 DVD Binary-1 20210814-10:04]/ bullseye contrib main deb bullseye-security

Cara Membuat Live USB VMWare ESXi 6.7 di Linux (Debian/CentOS)

VMWare ESXi 6.7 menyediakan satu installer dalam format CDROM ISO. Dalam tutorial kali ini kita akan membuat sebuah live USB dengan menggunakan sistem Linux, misalnya Debian dan CentOS. Untuk keperluan tutorial kali ini silakan pastikan sudah ada download installer ISO ESXi 6.7 dari Siapkan satu USB Flashdisk dengan kapasitas lebih dari 1GB. Format dalam satu partisi dengan tool yang biasa dipakai dalam format partisi FAT32. Misal dengan FDISK: [sourcecode] fdisk /dev/sdX [/sourcecode] format ke FAT32: [sourcecode]mkfs.fvat -F 32 -n USB /dev/sdX1[/sourcecode] selanjutnya, kita buat USB tersebut bootable dengan syslinux. Bagi linuxnya belum ada syslinux, silakan install dulu (apt-get install syslinux atau yum install syslinux).