Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 颤振语音\u到\u文本:^2.2.0程序包未侦听-初始化问题?_Android_Flutter_Package_Android Studio 3.0 - Fatal编程技术网

Android 颤振语音\u到\u文本:^2.2.0程序包未侦听-初始化问题?

Android 颤振语音\u到\u文本:^2.2.0程序包未侦听-初始化问题?,android,flutter,package,android-studio-3.0,Android,Flutter,Package,Android Studio 3.0,为了开始使用这个包,我尝试了开发人员提供的代码。 我在windows 7 64位机器上,使用过nexus 4,现在使用的是nexus 5x虚拟机和安卓5,现在使用的是安卓Q。除此之外,还有一款真正的安卓7.0手机。这款手机的车载文语转换功能完美无瑕。 在每种配置中,除非我单击initialize(初始化),否则界面不会真正响应-除了在Android Studio的Run(运行)窗口中,应用程序不会发生任何事情。 以下是读数: Launching lib\main.dart on Android

为了开始使用这个包,我尝试了开发人员提供的代码。 我在windows 7 64位机器上,使用过nexus 4,现在使用的是nexus 5x虚拟机和安卓5,现在使用的是安卓Q。除此之外,还有一款真正的安卓7.0手机。这款手机的车载文语转换功能完美无瑕。 在每种配置中,除非我单击initialize(初始化),否则界面不会真正响应-除了在Android Studio的Run(运行)窗口中,应用程序不会发生任何事情。 以下是读数:

Launching lib\main.dart on Android SDK built for x86 64 in debug mode... Running Gradle task 'assembleDebug'... √ Built build\app\outputs\apk\debug\app-debug.apk. Installing build\app\outputs\apk\app.apk... Flutter is taking longer than expected to report its views. Still trying... Debug service listening on ws://127.0.0.1:53319/B_tNUT2pR7I=/ws Syncing files to device Android SDK built for x86 64... W/xample.flutter( 5738): Accessing hidden method Landroid/view/accessibility/AccessibilityNodeInfo;->getSourceNodeId()J (greylist, reflection, allowed) W/xample.flutter( 5738): Accessing hidden method Landroid/view/accessibility/AccessibilityRecord;->getSourceNodeId()J (greylist, reflection, allowed) W/xample.flutter( 5738): Accessing hidden field Landroid/view/accessibility/AccessibilityNodeInfo;->mChildNodeIds:Landroid/util/LongArray; (greylist, reflection, allowed) W/xample.flutter( 5738): Accessing hidden method Landroid/util/LongArray;->get(I)J (greylist, reflection, allowed) I/Choreographer( 5738): Skipped 53 frames!  The application may be doing too much work on its main thread. D/HostConnection( 5738): HostConnection::get() New Host Connection established 0x70249825f180, tid 5786 D/HostConnection( 5738): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0  D/HostConnection( 5738): HostConnection::get() New Host Connection established 0x702497d3e6a0, tid 5955 D/HostConnection( 5738): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0  D/eglCodecCommon( 5738): setVertexArrayObject: set vao to 0 (0) 0 0 D/EGL_emulation( 5738): eglCreateContext: 0x702497d3e740: maj 3 min 0 rcv 3 D/eglCodecCommon( 5738): setVertexArrayObject: set vao to 0 (0) 0 0 D/EGL_emulation( 5738): eglCreateContext: 0x70249825f220: maj 3 min 0 rcv 3 D/EGL_emulation( 5738): eglMakeCurrent: 0x70249825f220: ver 3 0 (tinfo 0x702498218680) W/Gralloc3( 5738): mapper 3.x is not supported D/HostConnection( 5738): createUnique: call D/HostConnection( 5738): HostConnection::get() New Host Connection established 0x70249825f360, tid 5786 D/HostConnection( 5738): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0  D/eglCodecCommon( 5738): allocate: Ask for block of size 0x1000 D/eglCodecCommon( 5738): allocate: ioctl allocate returned offset 0x3ff807000 size 0x2000 D/HostConnection( 5738): createUnique: call D/HostConnection( 5738): HostConnection::get() New Host Connection established 0x702448a9ff00, tid 5955 D/HostConnection( 5738): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0  D/EGL_emulation( 5738): eglMakeCurrent: 0x702497d3e740: ver 3 0 (tinfo 0x70244d193360) D/EGL_emulation( 5738): eglMakeCurrent: 0x70249825f220: ver 3 0 (tinfo 0x702498218680) D/eglCodecCommon( 5738): setVertexArrayObject: set vao to 0 (0) 1 0 I/OpenGLRenderer( 5738): Davey! duration=16105ms; Flags=1, IntendedVsync=320862128930, Vsync=321745462228, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=321750930400, AnimationStart=321751011720, PerformTraversalsStart=321751071720, DrawStart=330820804190, SyncQueued=331199393480, SyncStart=331258181510, IssueDrawCommandsStart=331421431670, SwapBuffers=336112080650, FrameCompleted=337026255970, DequeueBufferDuration=550559000, QueueBufferDuration=35074000,  I/Choreographer( 5738): Skipped 953 frames!  The application may be doing too much work on its main thread. D/EGL_emulation( 5738): eglMakeCurrent: 0x702497d3e740: ver 3 0 (tinfo 0x70244d193360) D/eglCodecCommon( 5738): setVertexArrayObject: set vao to 0 (0) 0 0 I/Choreographer( 5738): Skipped 40 frames!  The application may be doing too much work on its main thread. I/OpenGLRenderer( 5738): Davey! duration=782ms; Flags=0, IntendedVsync=349271346526, Vsync=349938013166, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=349954335870, AnimationStart=349954427840, PerformTraversalsStart=349997031300, DrawStart=349997268140, SyncQueued=349997407090, SyncStart=350019841510, IssueDrawCommandsStart=350019994270, SwapBuffers=350027291360, FrameCompleted=350076153750, DequeueBufferDuration=149000, QueueBufferDuration=9594000,  I/OpenGLRenderer( 5738): Davey! duration=818ms; Flags=0, IntendedVsync=350655153383, Vsync=350755153379, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=350758548020, AnimationStart=350758679460, PerformTraversalsStart=350933225780, DrawStart=351140119140, SyncQueued=351140550980, SyncStart=351159859490, IssueDrawCommandsStart=351159930940, SwapBuffers=351165057370, FrameCompleted=351492805850, DequeueBufferDuration=292974000, QueueBufferDuration=727000,  W/xample.flutter( 5738): Verification of androidx.core.view.DragAndDropPermissionsCompat androidx.core.app.ActivityCompat.requestDragAndDropPermissions(android.app.Activity, android.view.DragEvent) took 201.593ms E/flutter ( 5738): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(multipleRequests, Only one initialize at a time, null) E/flutter ( 5738): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7) E/flutter ( 5738): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18) E/flutter ( 5738): <asynchronous suspension> E/flutter ( 5738): #2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12) E/flutter ( 5738): #3      SpeechToText.initialize (package:speech_to_text/speech_to_text.dart:174:10) E/flutter ( 5738):
#4      _MyAppState.initSpeechState (package:flutter6/main.dart:34:35) E/flutter ( 5738): #5      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:779:19) E/flutter ( 5738):
#6      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:862:36) E/flutter ( 5738):
#7      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24) E/flutter ( 5738): #8      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:504:11) E/flutter ( 5738): #9   BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:282:5) E/flutter ( 5738): #10   BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:217:7) E/flutter ( 5738): #11   PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:475:9) E/flutter ( 5738): #12     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:76:12) E/flutter ( 5738): #13     PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:122:9) E/flutter ( 5738): #14     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8) E/flutter ( 5738): #15 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:120:18) E/flutter ( 5738): #16     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:106:7) E/flutter ( 5738): #17     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19) E/flutter ( 5738):
#18     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22) E/flutter ( 5738):
#19     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7) E/flutter ( 5738):
#20     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7) E/flutter ( 5738):
#21     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7) E/flutter ( 5738):
#22     _rootRunUnary (dart:async/zone.dart:1196:13) E/flutter ( 5738): #23     _CustomZone.runUnary (dart:async/zone.dart:1085:19) E/flutter ( 5738): #24     _CustomZone.runUnaryGuarded (dart:async/zone.dart:987:7) E/flutter ( 5738): #25     _invoke1 (dart:ui/hooks.dart:275:10) E/flutter ( 5738): #26    
_dispatchPointerDataPacket (dart:ui/hooks.dart:184:5) E/flutter ( 5738):  I/Choreographer( 5738): Skipped 31 frames!  The application may be doing too much work on its main thread.
在调试模式下为x86 64构建的Android SDK上启动lib\main.dart。。。正在运行Gradle任务“assembleDebug”。。。√ 已生成build\app\outputs\apk\debug\app-debug.apk。正在安装build\app\outputs\apk\app.apk。。。弗利特报告其观点的时间比预期的要长。还在努力。。。调试服务侦听ws://127.0.0.1:53319/B_tNUT2pR7I=/ws将文件同步到为x86 64构建的设备Android SDK。。。W/示例颤振(5738):访问隐藏方法Landroid/view/accessibility/AccessibilityNodeInfo;->getSourceNodeId()J(greylist,reflection,allowed)W/example.flatter(5738):访问隐藏方法Landroid/view/accessibility/AccessibilityRecord;->getSourceNodeId()J(greylist,reflection,allowed)W/example.flatter(5738):访问隐藏字段Landroid/view/accessibility/AccessibilityNodeInfo;->mchildnodeid:Landroid/util/LongArray;(greylist,reflection,允许)W/example.flatter(5738):访问隐藏方法Landroid/util/LongArray;->获取(I)J(灰色列表,反射,允许)I/编舞(5738):跳过53帧!应用程序可能在其主线程上做了太多工作。D/HostConnection(5738):HostConnection::get()已建立新主机连接0x70249825f180,tid 5786 D/HostConnection(5738):HostComposition ext ANDROID_EMU_校验和_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_主机_composition_v2; ANDROID_EMU_YUV420_888___至NV21 ANDROID_EMU______缓存ANDROID_EMU_异步_取消映射_缓冲区GL_OES_EGL_图像_外部_ESSU OES L3________顶点数组_______纹理压缩ANDROID_EMU_gles_max_version_3_0 D/主机连接(5738):主机连接::get()建立新主机连接0x702497d3e6a0,tid 5955 D/主机连接(5738):HostComposition ext ANDROID_EMU_校验和_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_主机_composition_v2; ANDROID_EMU_YUV420_888___至NV21 ANDROID_EMU______缓存ANDROID_EMU_异步_取消映射_缓冲区GL_OES_EGL_图像_外部_ESSU OES L3________顶点数组_______纹理压缩ANDROID_EMU_gles_max_version_3_0 D/eglcodeccon(5738):setVertexArrayObject:将vao设置为0(0)0 D/EGL_仿真(5738):eglCreateContext:0x702497d3e740:maj 3 min 0 rcv 3 D/eglcodeccon(5738):setVertexArrayObject:将vao设置为0(0)0 0 D/EGL_仿真(5738):eglCreateContext:0x70249825f220:maj 3 min 0 rcv 3 D/EGL_仿真(5738):eglMakeCurrent:0x70249825f220:ver 3 0(tinfo 0x702498218680)W/Gralloc3(5738):不支持映射器3.x D/HostConnection(5738):createUnique:调用D/HostConnection(5738):HostConnection::get()已建立新主机连接0x70249825f360,tid 5786 D/HostConnection(5738):HostComposition ext ANDROID_EMU_校验和_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_主机_composition_v2; ANDROID_EMU_YUV420_888___至NV21 ANDROID_EMU______缓存ANDROID_EMU_异步_取消映射_缓冲区GL_OES_EGL_图像_外部_ESSU OES L3________顶点数组_______纹理压缩ANDROID\u EMU\u gles\u max\u version\u 3\u 0 D/eglcodecommon(5738):分配:请求大小为0x1000 D/eglcodecommon(5738)的块:分配:ioctl分配返回的偏移量0x3ff807000大小为0x2000 D/HostConnection(5738):createUnique:call D/HostConnection(5738):HostConnection::get()新主机连接已建立0x702448a9ff00,tid 5955 D/主机连接(5738):HostComposition ext ANDROID_EMU_校验和_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_主机_composition_v2; ANDROID_EMU_YUV420_888___至NV21 ANDROID_EMU______缓存ANDROID_EMU_异步_取消映射_缓冲区GL_OES_EGL_图像_外部_ESSU OES L3________顶点数组_______纹理压缩ANDROID_EMU_gles_max_version_3_0 D/EGL_仿真(5738):eglmakeecurrent:0x702497d3e740:ver3 0(tinfo 0x70244d193360)D/EGL_仿真(5738):eglmakeecurrent:0x70249825f220:ver3 0(tinfo 0x702498218680)D/eglcodeccon(5738):setVertexArrayObject:setvao为0(0)1i/OpenGLRenderer(5738):Davey!持续时间=16105ms;Flags=1,IntentendedVsync=320862128930,Vsync=321745462228,OldestInputEvent=9223372036854775807,NewestInputEvent=0,HandleInputStart=321750930400,AnimationStart=321751011720,PerformTraversalsStart=321751071720,DrawStart=3308204190,SyncQueued=33119933480,SyncStart=3312581510,IssueDrawCommandsStart=331421431670,SwapBuffers=3361180650,FrameCompleted=337026255970,DequeueBufferDuration=550559000,QueueBufferDuration=35074000,I/Choreographer(5738):跳过953帧!应用程序可能在其主线程上做了太多工作。D/EGL_仿真(5738):eglMakeCurrent:0x702497d3e740:ver 30(tinfo 0x70244d193360)D/eglCodecCommon(5738):setVertexArrayObject:将vao设置为0(0)0I/编舞器(5738):跳过40帧!应用程序可能在其主线程上做了太多工作。I/OpenGLRenderer(5738):戴维!持续时间=782ms;Flags=0,IntendedVsync=349271346526,Vsync=349938013166,OldestInputEvent=9223372036854775807,NewestInputEvent=0,HandleInputStart=349954335870,AnimationStart=349954427840,PerformTraversalsStart=349997031300,DrawStart=349997268140,SyncQueued=349997407090,SyncStart=350019841510,IssueDrawCommandsStart=3500942270,SwapBuffers=35002711360,FrameCompleted=350076153750,DequeueBufferDuration=149000,QueueBufferDuration=9594000,I/OpenGLRenderer(5738):Davey!杜尔
import 'dart:async';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:speech_to_text/speech_recognition_error.dart';
import 'package:speech_to_text/speech_recognition_result.dart';
import 'package:speech_to_text/speech_to_text.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool _hasSpeech = false;
  double level = 0.0;
  double minSoundLevel = 50000;
  double maxSoundLevel = -50000;
  String lastWords = "";
  String lastError = "";
  String lastStatus = "";
  String _currentLocaleId = "";
  List<LocaleName> _localeNames = [];
  final SpeechToText speech = SpeechToText();

  @override
  void initState() {
    super.initState();
  }

  Future<void> initSpeechState() async {
    bool hasSpeech = await speech.initialize(
        onError: errorListener, onStatus: statusListener);
    if (hasSpeech) {
      _localeNames = await speech.locales();

      var systemLocale = await speech.systemLocale();
      _currentLocaleId = systemLocale.localeId;
    }

    if (!mounted) return;

    setState(() {
      _hasSpeech = hasSpeech;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Speech to Text Example'),
        ),
        body: Column(children: [
          Center(
            child: Text(
              'Speech recognition available',
              style: TextStyle(fontSize: 22.0),
            ),
          ),
          Container(
            child: Column(
              children: <Widget>[
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: <Widget>[
                    FlatButton(
                      child: Text('Initialize'),
                      onPressed: _hasSpeech ? null : initSpeechState,
                    ),
                  ],
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: <Widget>[
                    FlatButton(
                      child: Text('Start'),
                      onPressed: !_hasSpeech || speech.isListening
                          ? null
                          : startListening,
                    ),
                    FlatButton(
                      child: Text('Stop'),
                      onPressed: speech.isListening ? stopListening : null,
                    ),
                    FlatButton(
                      child: Text('Cancel'),
                      onPressed: speech.isListening ? cancelListening : null,
                    ),
                  ],
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: <Widget>[
                    DropdownButton(
                      onChanged: (selectedVal) => _switchLang(selectedVal),
                      value: _currentLocaleId,
                      items: _localeNames
                          .map(
                            (localeName) => DropdownMenuItem(
                          value: localeName.localeId,
                          child: Text(localeName.name),
                        ),
                      )
                          .toList(),
                    ),
                  ],
                )
              ],
            ),
          ),
          Expanded(
            flex: 4,
            child: Column(
              children: <Widget>[
                Center(
                  child: Text(
                    'Recognized Words',
                    style: TextStyle(fontSize: 22.0),
                  ),
                ),
                Expanded(
                  child: Stack(
                    children: <Widget>[
                      Container(
                        color: Theme.of(context).selectedRowColor,
                        child: Center(
                          child: Text(
                            lastWords,
                            textAlign: TextAlign.center,
                          ),
                        ),
                      ),
                      Positioned.fill(
                        bottom: 10,
                        child: Align(
                          alignment: Alignment.bottomCenter,
                          child: Container(
                            width: 40,
                            height: 40,
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                              boxShadow: [
                                BoxShadow(
                                    blurRadius: .26,
                                    spreadRadius: level * 1.5,
                                    color: Colors.black.withOpacity(.05))
                              ],
                              color: Colors.white,
                              borderRadius:
                              BorderRadius.all(Radius.circular(50)),
                            ),
                            child: IconButton(icon: Icon(Icons.mic),

                                onPressed: () {
                              /*...*/
                            }
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
          Expanded(
            flex: 1,
            child: Column(
              children: <Widget>[
                Center(
                  child: Text(
                    'Error Status',
                    style: TextStyle(fontSize: 22.0),
                  ),
                ),
                Center(
                  child: Text(lastError),
                ),
              ],
            ),
          ),
          Container(
            padding: EdgeInsets.symmetric(vertical: 20),
            color: Theme.of(context).backgroundColor,
            child: Center(
              child: speech.isListening
                  ? Text(
                "I'm listening...",
                style: TextStyle(fontWeight: FontWeight.bold),
              )
                  : Text(
                'Not listening',
                style: TextStyle(fontWeight: FontWeight.bold),
              ),
            ),
          ),
        ]),
      ),
    );
  }

  void startListening() {
    lastWords = "";
    lastError = "";
    speech.listen(
        onResult: resultListener,
        listenFor: Duration(seconds: 10),
        localeId: _currentLocaleId,
        onSoundLevelChange: soundLevelListener,
        cancelOnError: true,
        partialResults: true);
    setState(() {});
  }

  void stopListening() {
    speech.stop();
    setState(() {
      level = 0.0;
    });
  }

  void cancelListening() {
    speech.cancel();
    setState(() {
      level = 0.0;
    });
  }

  void resultListener(SpeechRecognitionResult result) {
    setState(() {
      lastWords = "${result.recognizedWords} - ${result.finalResult}";
    });
  }

  void soundLevelListener(double level) {
    minSoundLevel = min(minSoundLevel, level);
    maxSoundLevel = max(maxSoundLevel, level);
    //print("sound level $level: $minSoundLevel - $maxSoundLevel ");
    setState(() {
      this.level = level;
    });
  }

  void errorListener(SpeechRecognitionError error) {
    print("Received error status: $error, listening: ${speech.isListening}");
    setState(() {
      lastError = "${error.errorMsg} - ${error.permanent}";
    });
  }

  void statusListener(String status) {
    print(
        "Received listener status: $status, listening: ${speech.isListening}");
    setState(() {
      lastStatus = "$status";
    });
  }

  _switchLang(selectedVal) {
    setState(() {
      _currentLocaleId = selectedVal;
    });
    print(selectedVal);
  }
}