{"id":332864,"date":"2022-05-06T15:00:46","date_gmt":"2022-05-06T15:00:46","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=332864"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=332864","title":{"rendered":"<span>\u0421\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 \u043d\u0430 Flutter<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043e\u043f\u044b\u0442\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043b\u0435\u0433\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043f\u0440\u043e\u0433\u043e\u0432\u0430\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0444\u0440\u0430\u0437\u0435 \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438.<\/p>\n<p>\u041e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u043b \u0437\u0430\u043a\u0430\u0437 \u043d\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0442\u0440\u0435\u043d\u0430\u0436\u0435\u0440\u0430 \u0433\u043e\u0432\u043e\u0440\u0435\u043d\u0438\u044f \u043d\u0430 \u0438\u043d\u043e\u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445. \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0440\u0430\u0437\u0430, \u043e\u043d \u0435\u0435 \u043f\u0440\u043e\u0438\u0437\u043d\u043e\u0441\u0438\u0442, \u0438 \u043f\u043e \u043c\u0435\u0440\u0435 \u043f\u0440\u043e\u0438\u0437\u043d\u043e\u0448\u0435\u043d\u0438\u044f (\u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u043d\u043e\u0448\u0435\u043d\u0438\u044f) \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0431\u043b\u043e\u043a \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 \u043a\u0430\u0440\u0430\u043e\u043a\u0435 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438.<\/p>\n<p>\u0417\u0430 \u043e\u0441\u043d\u043e\u0432\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0431\u044b\u043b \u0432\u0437\u044f\u0442 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u00a0example \u0441 pub.dev <a href=\"https:\/\/pub.dev\/packages\/speech_to_text\/example\" rel=\"noopener noreferrer nofollow\">https:\/\/pub.dev\/packages\/speech_to_text\/example<\/a><\/p>\n<pre><code class=\"dart\">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(SpeechSampleApp());  class SpeechSampleApp extends StatefulWidget {   @override   _SpeechSampleAppState createState() => _SpeechSampleAppState(); }  \/\/\/ An example that demonstrates the basic functionality of the \/\/\/ SpeechToText plugin for using the speech recognition capability \/\/\/ of the underlying platform. class _SpeechSampleAppState extends State&lt;SpeechSampleApp> {   bool _hasSpeech = false;   bool _logEvents = false;   double level = 0.0;   double minSoundLevel = 50000;   double maxSoundLevel = -50000;   String lastWords = '';   String lastError = '';   String lastStatus = '';   String _currentLocaleId = '';   List&lt;LocaleName> _localeNames = [];   final SpeechToText speech = SpeechToText();    @override   void initState() {     super.initState();   }    \/\/\/ This initializes SpeechToText. That only has to be done   \/\/\/ once per application, though calling it again is harmless   \/\/\/ it also does nothing. The UX of the sample app ensures that   \/\/\/ it can only be called once.   Future&lt;void> initSpeechState() async {     _logEvent('Initialize');     try {       var hasSpeech = await speech.initialize(         onError: errorListener,         onStatus: statusListener,         debugLogging: true,       );       if (hasSpeech) {         \/\/ Get the list of languages installed on the supporting platform so they         \/\/ can be displayed in the UI for selection by the user.         _localeNames = await speech.locales();          var systemLocale = await speech.systemLocale();         _currentLocaleId = systemLocale?.localeId ?? '';       }       if (!mounted) return;        setState(() {         _hasSpeech = hasSpeech;       });     } catch (e) {       setState(() {         lastError = 'Speech recognition failed: ${e.toString()}';         _hasSpeech = false;       });     }   }    @override   Widget build(BuildContext context) {     return MaterialApp(       home: Scaffold(         appBar: AppBar(           title: const Text('Speech to Text Example'),         ),         body: Column(children: [           HeaderWidget(),           Container(             child: Column(               children: &lt;Widget>[                 InitSpeechWidget(_hasSpeech, initSpeechState),                 SpeechControlWidget(_hasSpeech, speech.isListening,                     startListening, stopListening, cancelListening),                 SessionOptionsWidget(_currentLocaleId, _switchLang,                     _localeNames, _logEvents, _switchLogging),               ],             ),           ),           Expanded(             flex: 4,             child: RecognitionResultsWidget(lastWords: lastWords, level: level),           ),           Expanded(             flex: 1,             child: ErrorWidget(lastError: lastError),           ),           SpeechStatusWidget(speech: speech),         ]),       ),     );   }    \/\/ This is called each time the users wants to start a new speech   \/\/ recognition session   void startListening() {     _logEvent('start listening');     lastWords = '';     lastError = '';     \/\/ Note that `listenFor` is the maximum, not the minimun, on some     \/\/ recognition will be stopped before this value is reached.     \/\/ Similarly `pauseFor` is a maximum not a minimum and may be ignored     \/\/ on some devices.     speech.listen(         onResult: resultListener,         listenFor: Duration(seconds: 30),         pauseFor: Duration(seconds: 5),         partialResults: true,         localeId: _currentLocaleId,         onSoundLevelChange: soundLevelListener,         cancelOnError: true,         listenMode: ListenMode.confirmation);     setState(() {});   }    void stopListening() {     _logEvent('stop');     speech.stop();     setState(() {       level = 0.0;     });   }    void cancelListening() {     _logEvent('cancel');     speech.cancel();     setState(() {       level = 0.0;     });   }    \/\/\/ This callback is invoked each time new recognition results are   \/\/\/ available after `listen` is called.   void resultListener(SpeechRecognitionResult result) {     _logEvent(         'Result listener final: ${result.finalResult}, words: ${result.recognizedWords}');     setState(() {       lastWords = '${result.recognizedWords} - ${result.finalResult}';     });   }    void soundLevelListener(double level) {     minSoundLevel = min(minSoundLevel, level);     maxSoundLevel = max(maxSoundLevel, level);     \/\/ _logEvent('sound level $level: $minSoundLevel - $maxSoundLevel ');     setState(() {       this.level = level;     });   }    void errorListener(SpeechRecognitionError error) {     _logEvent(         'Received error status: $error, listening: ${speech.isListening}');     setState(() {       lastError = '${error.errorMsg} - ${error.permanent}';     });   }    void statusListener(String status) {     _logEvent(         'Received listener status: $status, listening: ${speech.isListening}');     setState(() {       lastStatus = '$status';     });   }    void _switchLang(selectedVal) {     setState(() {       _currentLocaleId = selectedVal;     });     print(selectedVal);   }    void _logEvent(String eventDescription) {     if (_logEvents) {       var eventTime = DateTime.now().toIso8601String();       print('$eventTime $eventDescription');     }   }    void _switchLogging(bool? val) {     setState(() {       _logEvents = val ?? false;     });   } }  \/\/\/ Displays the most recently recognized words and the sound level. class RecognitionResultsWidget extends StatelessWidget {   const RecognitionResultsWidget({     Key? key,     required this.lastWords,     required this.level,   }) : super(key: key);    final String lastWords;   final double level;    @override   Widget build(BuildContext context) {     return Column(       children: &lt;Widget>[         Center(           child: Text(             'Recognized Words',             style: TextStyle(fontSize: 22.0),           ),         ),         Expanded(           child: Stack(             children: &lt;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: () => null,                     ),                   ),                 ),               ),             ],           ),         ),       ],     );   } }  class HeaderWidget extends StatelessWidget {   const HeaderWidget({     Key? key,   }) : super(key: key);    @override   Widget build(BuildContext context) {     return Center(       child: Text(         'Speech recognition available',         style: TextStyle(fontSize: 22.0),       ),     );   } }  \/\/\/ Display the current error status from the speech \/\/\/ recognizer class ErrorWidget extends StatelessWidget {   const ErrorWidget({     Key? key,     required this.lastError,   }) : super(key: key);    final String lastError;    @override   Widget build(BuildContext context) {     return Column(       children: &lt;Widget>[         Center(           child: Text(             'Error Status',             style: TextStyle(fontSize: 22.0),           ),         ),         Center(           child: Text(lastError),         ),       ],     );   } }  \/\/\/ Controls to start and stop speech recognition class SpeechControlWidget extends StatelessWidget {   const SpeechControlWidget(this.hasSpeech, this.isListening,       this.startListening, this.stopListening, this.cancelListening,       {Key? key})       : super(key: key);    final bool hasSpeech;   final bool isListening;   final void Function() startListening;   final void Function() stopListening;   final void Function() cancelListening;    @override   Widget build(BuildContext context) {     return Row(       mainAxisAlignment: MainAxisAlignment.spaceAround,       children: &lt;Widget>[         TextButton(           onPressed: !hasSpeech || isListening ? null : startListening,           child: Text('Start'),         ),         TextButton(           onPressed: isListening ? stopListening : null,           child: Text('Stop'),         ),         TextButton(           onPressed: isListening ? cancelListening : null,           child: Text('Cancel'),         )       ],     );   } }  class SessionOptionsWidget extends StatelessWidget {   const SessionOptionsWidget(this.currentLocaleId, this.switchLang,       this.localeNames, this.logEvents, this.switchLogging,       {Key? key})       : super(key: key);    final String currentLocaleId;   final void Function(String?) switchLang;   final void Function(bool?) switchLogging;   final List&lt;LocaleName> localeNames;   final bool logEvents;    @override   Widget build(BuildContext context) {     return Padding(       padding: const EdgeInsets.all(8.0),       child: Column(         mainAxisAlignment: MainAxisAlignment.spaceBetween,         children: &lt;Widget>[           Row(             children: [               Text('Language: '),               DropdownButton&lt;String>(                 onChanged: (selectedVal) => switchLang(selectedVal),                 value: currentLocaleId,                 items: localeNames                     .map(                       (localeName) => DropdownMenuItem(                         value: localeName.localeId,                         child: Text(localeName.name),                       ),                     )                     .toList(),               ),             ],           ),           Row(             children: [               Text('Log events: '),               Checkbox(                 value: logEvents,                 onChanged: switchLogging,               ),             ],           )         ],       ),     );   } }  class InitSpeechWidget extends StatelessWidget {   const InitSpeechWidget(this.hasSpeech, this.initSpeechState, {Key? key})       : super(key: key);    final bool hasSpeech;   final Future&lt;void> Function() initSpeechState;    @override   Widget build(BuildContext context) {     return Row(       mainAxisAlignment: MainAxisAlignment.spaceAround,       children: &lt;Widget>[         TextButton(           onPressed: hasSpeech ? null : initSpeechState,           child: Text('Initialize'),         ),       ],     );   } }  \/\/\/ Display the current status of the listener class SpeechStatusWidget extends StatelessWidget {   const SpeechStatusWidget({     Key? key,     required this.speech,   }) : super(key: key);    final SpeechToText speech;    @override   Widget build(BuildContext context) {     return 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),               ),       ),     );   } }<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u044b\u043b \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0430\u043a\u0435\u0442 (<a href=\"https:\/\/pub.dev\/packages\/speech_to_text\/versions\" rel=\"noopener noreferrer nofollow\">https:\/\/pub.dev\/packages\/speech_to_text\/versions<\/a>), \u043d\u043e \u043e\u043d, \u0445\u043e\u0442\u044c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 iOS speech \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u043b \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u043f\u0440\u043e\u0433\u043e\u0432\u0430\u0440\u0438\u0432\u0430\u043d\u0438\u044f \u0444\u0440\u0430\u0437\u044b \u0438 \u043f\u0430\u0443\u0437\u044b.<\/p>\n<p>\u0417\u0430\u043a\u0430\u0437\u0447\u0438\u043a \u043e\u0433\u043e\u0432\u0430\u0440\u0438\u0432\u0430\u043b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u0434\u043b\u044f iOS, \u043d\u043e Flutter \u0431\u044b\u043b \u0432\u044b\u0431\u0440\u0430\u043d \u043a\u0430\u043a \u0437\u0430\u0434\u0435\u043b \u043d\u0430 \u0431\u0443\u0434\u0443\u0449\u0435\u0435 \u0442.\u043a. \u0438\u043c\u0435\u043b\u0430\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043b\u0435\u0433\u043a\u043e \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u044b\u0448\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0434 Android.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0437\u0431\u043e\u0440\u0430 \u043f\u0440\u043e\u0438\u0437\u043d\u043e\u0441\u0438\u043c\u043e\u0439 \u0444\u0440\u0430\u0437\u044b \u043d\u0430 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u0438 \u043d\u0435 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0431\u044b\u043b\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0430\u044f RichText:<\/p>\n<pre><code class=\"dart\">List&lt;TextSpan> highlightOccurrences(String source, String query) {   if (query == null || query.isEmpty || !source.toLowerCase().contains(query.toLowerCase())) {     \/\/startSpech = false;     return [ TextSpan(text: source) ];   }    final matches = query.toLowerCase().allMatches(source.toLowerCase());    int lastMatchEnd = 0;    final List&lt;TextSpan> children = [];   for (var i = 0; i &lt; matches.length; i++) {     final match = matches.elementAt(i);      if (match.start != lastMatchEnd) {       children.add(TextSpan(         text: source.substring(lastMatchEnd, match.start),       ));     }      children.add(TextSpan(       text: source.substring(match.start, match.end),       style: const TextStyle(fontWeight: FontWeight.bold, color: Colors.black),     ));      if (i == matches.length - 1 &amp;&amp; match.end != source.length) {       children.add(TextSpan(         text: source.substring(match.end, source.length),       ));     }      lastMatchEnd = match.end;   }   return children; }<\/code><\/pre>\n<p>\u0412\u0441\u0435 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e, \u043d\u043e \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u043d\u0435\u043a\u0442\u043e\u0440\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f &#171;\u043d\u0430\u043f\u0438\u043b\u044c\u043d\u0438\u043a\u043e\u043c&#187;.<\/p>\n<ol>\n<li>\n<p>\u043f\u0435\u0440\u0435\u0434 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435\u043c \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u043d\u043d\u043e\u0439 \u0438 \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u043e\u0439 \u0444\u0440\u0430\u0437\u044b \u043d\u0430\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0432\u0441\u0435 \u0432 \u043d\u0438\u0436\u043d\u0438\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440, \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u0435\u043b\u044b, \u043b\u044e\u0431\u044b\u0435 \u0441\u043f\u0435\u0446-\u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0438 \u0437\u043d\u0430\u043a\u0438 \u043f\u0440\u0435\u043f\u0438\u043d\u0430\u043d\u0438\u044f, \u0430 \u0442\u0430\u043a \u0436\u0435 \u0441\u043a\u0440\u044b\u0442\u044b\u0435 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u044b \u0438 \u0442\u0430\u0431\u044b.<\/p>\n<\/li>\n<li>\n<p>\u042d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043d\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0439,  \u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0441\u043b\u043e\u0432 \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c \u0441\u043b\u043e\u0432. \u0422\u0430\u043a \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u0445\u043e\u0434\u0438\u0442\u044c \u043d\u0435 \u043b\u044e\u0431\u0438\u043c\u044b\u0435 speech_\u0435\u043c \u044f\u043c\u043a\u0438 \u043f\u0440\u0438 \u043f\u043b\u043e\u0445\u043e\u043c \u043f\u0440\u043e\u0438\u0437\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u0438 \u0444\u0440\u0430\u0437\u0430\u0445 \u0442\u0438\u043f\u0430 \u041f\u0443\u0448\u043a\u0438\u043d\u0441\u043a\u0438\u0445 \u0441\u043b\u043e\u0433\u043e\u0432. <\/p>\n<p><code>\u041c\u043e\u0440\u043e\u0437 \u0438 \u0441\u043e\u043b\u043d\u0446\u0435; \u0434\u0435\u043d\u044c \u0447\u0443\u0434\u0435\u0441\u043d\u044b\u0439!<br \/>\u0415\u0449\u0435 \u0442\u044b \u0434\u0440\u0435\u043c\u043b\u0435\u0448\u044c, \u0434\u0440\u0443\u0433 \u043f\u0440\u0435\u043b\u0435\u0441\u0442\u043d\u044b\u0439\u00a0\u2014<br \/>\u041f\u043e\u0440\u0430, \u043a\u0440\u0430\u0441\u0430\u0432\u0438\u0446\u0430, \u043f\u0440\u043e\u0441\u043d\u0438\u0441\u044c:<br \/>\u041e\u0442\u043a\u0440\u043e\u0439 \u0441\u043e\u043c\u043a\u043d\u0443\u0442\u044b \u043d\u0435\u0433\u043e\u0439 \u0432\u0437\u043e\u0440\u044b<br \/>\u041d\u0430\u0432\u0441\u0442\u0440\u0435\u0447\u0443 \u0441\u0435\u0432\u0435\u0440\u043d\u043e\u0439 \u0410\u0432\u0440\u043e\u0440\u044b,<br \/>\u0417\u0432\u0435\u0437\u0434\u043e\u044e \u0441\u0435\u0432\u0435\u0440\u0430 \u044f\u0432\u0438\u0441\u044c!<\/code><\/p>\n<p>\u043b\u0443\u0447\u0448\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0434\u043e\u0433\u043d\u0430\u043d\u043d\u044b\u043c \u043f\u043e\u0434 speech <\/p>\n<p><code>\u041c\u043e\u0440\u043e\u0437 \u0438 \u0441\u043e\u043b\u043d\u0446\u0435 \u0434\u0435\u043d\u044c \u0447\u0443\u0434\u0435\u0441\u043d\u044b\u0439 \u0415\u0449\u0451 \u0442\u044b \u0434\u0440\u0435\u043c\u043b\u0435\u0448\u044c \u0434\u0440\u0443\u0433 \u043f\u0440\u0435\u043b\u0435\u0441\u0442\u043d\u044b\u0439 \u041f\u043e\u0440\u0430 \u043a\u0440\u0430\u0441\u0430\u0432\u0438\u0446\u0430 \u043f\u0440\u043e\u0441\u043d\u0438\u0441\u044c \u041e\u0442\u043a\u0440\u043e\u0439 \u0441\u043e\u043c\u043a\u043d\u0443\u0442\u044b\u0435 \u043d\u0435\u0433\u043e\u0439 \u0432\u0437\u043e\u0440\u044b \u041d\u0430\u0432\u0441\u0442\u0440\u0435\u0447\u0443 \u0441\u0435\u0432\u0435\u0440\u043d\u043e\u0439 \u0410\u0432\u0440\u043e\u0440\u044b \u0417\u0432\u0435\u0437\u0434\u043e\u044e \u0441\u0435\u0432\u0435\u0440\u0430 \u044f\u0432\u0438\u0441\u044c<\/code><\/p>\n<\/li>\n<\/ol>\n<p>\u041e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u0438 \u043d\u0435 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u0440\u0430\u0434\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044f \u043f\u0438\u0448\u0443 \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e \u0432 \u043d\u0430\u0434\u0435\u0436\u0434\u0435 \u043d\u0430 \u0441\u043e\u0432\u0435\u0442\u044b.<\/p>\n<ol>\n<li>\n<p>Listener \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0440\u0430\u0439\u043d\u0435 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e \u0438 \u043f\u0440\u0438 \u0431\u044b\u0441\u0442\u0440\u043e\u043c \u0433\u043e\u0432\u043e\u0440\u0435\u043d\u0438\u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u044c \u0438 \u0440\u0430\u0437\u043c\u0435\u0447\u0430\u0442\u044c \u0442\u0430\u043a\u0441, \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0438\u043b\u044c\u043d\u044b\u0439 \u043b\u0430\u0433<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 speech \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0440\u0430\u0439\u043d\u0435 \u043f\u043b\u043e\u0445\u043e \u0438 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u043e\u0433\u043e\u0432\u043e\u0440\u043a\u0430\u043c\u0438. \u0420\u0430\u0437 \u0441\u0442\u0430\u0440\u0430\u0435\u0442\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u043a 1, &#171;\u041f\u0443\u0448\u043a\u0438\u043d\u0441\u043a\u0438\u0439 \u0441\u043b\u043e\u0433&#187; \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043c\u0438\u0440\u0441\u043a\u043e\u0439 \u0438 \u0442.\u0434.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043b\u0438\u0435\u043d\u0442 \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c CMU Sphinx <a href=\"https:\/\/cmusphinx.github.io\/wiki\/download\/\" rel=\"noopener noreferrer nofollow\">https:\/\/cmusphinx.github.io\/wiki\/download\/<\/a>, \u043d\u043e \u043e\u043d \u043d\u0435 \u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 iOS.<\/p>\n<\/li>\n<\/ol>\n<p>\u0411\u0443\u0434\u0443 \u0440\u0430\u0434 \u043b\u044e\u0431\u044b\u043c \u0441\u043e\u0432\u0435\u0442\u0430\u043c \u0438 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f\u043c! \u041f\u0440\u043e\u0441\u044c\u0431\u0430 \u0441\u0438\u043b\u044c\u043d\u043e \u043d\u0435 \u0431\u0443\u043b\u0438\u0442\u044c, \u044d\u0442\u043e \u043c\u043e\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430 \u0425\u0430\u0431\u0440 \ud83d\ude42<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/664658\/\"> https:\/\/habr.com\/ru\/post\/664658\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043e\u043f\u044b\u0442\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043b\u0435\u0433\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043f\u0440\u043e\u0433\u043e\u0432\u0430\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0444\u0440\u0430\u0437\u0435 \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438.<\/p>\n<p>\u041e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u043b \u0437\u0430\u043a\u0430\u0437 \u043d\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0442\u0440\u0435\u043d\u0430\u0436\u0435\u0440\u0430 \u0433\u043e\u0432\u043e\u0440\u0435\u043d\u0438\u044f \u043d\u0430 \u0438\u043d\u043e\u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445. \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0440\u0430\u0437\u0430, \u043e\u043d \u0435\u0435 \u043f\u0440\u043e\u0438\u0437\u043d\u043e\u0441\u0438\u0442, \u0438 \u043f\u043e \u043c\u0435\u0440\u0435 \u043f\u0440\u043e\u0438\u0437\u043d\u043e\u0448\u0435\u043d\u0438\u044f (\u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u043d\u043e\u0448\u0435\u043d\u0438\u044f) \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0431\u043b\u043e\u043a \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 \u043a\u0430\u0440\u0430\u043e\u043a\u0435 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438.<\/p>\n<p>\u0417\u0430 \u043e\u0441\u043d\u043e\u0432\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0431\u044b\u043b \u0432\u0437\u044f\u0442 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u00a0example \u0441 pub.dev <a href=\"https:\/\/pub.dev\/packages\/speech_to_text\/example\" rel=\"noopener noreferrer nofollow\">https:\/\/pub.dev\/packages\/speech_to_text\/example<\/a><\/p>\n<pre><code class=\"dart\">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(SpeechSampleApp());  class SpeechSampleApp extends StatefulWidget {   @override   _SpeechSampleAppState createState() => _SpeechSampleAppState(); }  \/\/\/ An example that demonstrates the basic functionality of the \/\/\/ SpeechToText plugin for using the speech recognition capability \/\/\/ of the underlying platform. class _SpeechSampleAppState extends State&lt;SpeechSampleApp> {   bool _hasSpeech = false;   bool _logEvents = false;   double level = 0.0;   double minSoundLevel = 50000;   double maxSoundLevel = -50000;   String lastWords = '';   String lastError = '';   String lastStatus = '';   String _currentLocaleId = '';   List&lt;LocaleName> _localeNames = [];   final SpeechToText speech = SpeechToText();    @override   void initState() {     super.initState();   }    \/\/\/ This initializes SpeechToText. That only has to be done   \/\/\/ once per application, though calling it again is harmless   \/\/\/ it also does nothing. The UX of the sample app ensures that   \/\/\/ it can only be called once.   Future&lt;void> initSpeechState() async {     _logEvent('Initialize');     try {       var hasSpeech = await speech.initialize(         onError: errorListener,         onStatus: statusListener,         debugLogging: true,       );       if (hasSpeech) {         \/\/ Get the list of languages installed on the supporting platform so they         \/\/ can be displayed in the UI for selection by the user.         _localeNames = await speech.locales();          var systemLocale = await speech.systemLocale();         _currentLocaleId = systemLocale?.localeId ?? '';       }       if (!mounted) return;        setState(() {         _hasSpeech = hasSpeech;       });     } catch (e) {       setState(() {         lastError = 'Speech recognition failed: ${e.toString()}';         _hasSpeech = false;       });     }   }    @override   Widget build(BuildContext context) {     return MaterialApp(       home: Scaffold(         appBar: AppBar(           title: const Text('Speech to Text Example'),         ),         body: Column(children: [           HeaderWidget(),           Container(             child: Column(               children: &lt;Widget>[                 InitSpeechWidget(_hasSpeech, initSpeechState),                 SpeechControlWidget(_hasSpeech, speech.isListening,                     startListening, stopListening, cancelListening),                 SessionOptionsWidget(_currentLocaleId, _switchLang,                     _localeNames, _logEvents, _switchLogging),               ],             ),           ),           Expanded(             flex: 4,             child: RecognitionResultsWidget(lastWords: lastWords, level: level),           ),           Expanded(             flex: 1,             child: ErrorWidget(lastError: lastError),           ),           SpeechStatusWidget(speech: speech),         ]),       ),     );   }    \/\/ This is called each time the users wants to start a new speech   \/\/ recognition session   void startListening() {     _logEvent('start listening');     lastWords = '';     lastError = '';     \/\/ Note that `listenFor` is the maximum, not the minimun, on some     \/\/ recognition will be stopped before this value is reached.     \/\/ Similarly `pauseFor` is a maximum not a minimum and may be ignored     \/\/ on some devices.     speech.listen(         onResult: resultListener,         listenFor: Duration(seconds: 30),         pauseFor: Duration(seconds: 5),         partialResults: true,         localeId: _currentLocaleId,         onSoundLevelChange: soundLevelListener,         cancelOnError: true,         listenMode: ListenMode.confirmation);     setState(() {});   }    void stopListening() {     _logEvent('stop');     speech.stop();     setState(() {       level = 0.0;     });   }    void cancelListening() {     _logEvent('cancel');     speech.cancel();     setState(() {       level = 0.0;     });   }    \/\/\/ This callback is invoked each time new recognition results are   \/\/\/ available after `listen` is called.   void resultListener(SpeechRecognitionResult result) {     _logEvent(         'Result listener final: ${result.finalResult}, words: ${result.recognizedWords}');     setState(() {       lastWords = '${result.recognizedWords} - ${result.finalResult}';     });   }    void soundLevelListener(double level) {     minSoundLevel = min(minSoundLevel, level);     maxSoundLevel = max(maxSoundLevel, level);     \/\/ _logEvent('sound level $level: $minSoundLevel - $maxSoundLevel ');     setState(() {       this.level = level;     });   }    void errorListener(SpeechRecognitionError error) {     _logEvent(         'Received error status: $error, listening: ${speech.isListening}');     setState(() {       lastError = '${error.errorMsg} - ${error.permanent}';     });   }    void statusListener(String status) {     _logEvent(         'Received listener status: $status, listening: ${speech.isListening}');     setState(() {       lastStatus = '$status';     });   }    void _switchLang(selectedVal) {     setState(() {       _currentLocaleId = selectedVal;     });     print(selectedVal);   }    void _logEvent(String eventDescription) {     if (_logEvents) {       var eventTime = DateTime.now().toIso8601String();       print('$eventTime $eventDescription');     }   }    void _switchLogging(bool? val) {     setState(() {       _logEvents = val ?? false;     });   } }  \/\/\/ Displays the most recently recognized words and the sound level. class RecognitionResultsWidget extends StatelessWidget {   const RecognitionResultsWidget({     Key? key,     required this.lastWords,     required this.level,   }) : super(key: key);    final String lastWords;   final double level;    @override   Widget build(BuildContext context) {     return Column(       children: &lt;Widget>[         Center(           child: Text(             'Recognized Words',             style: TextStyle(fontSize: 22.0),           ),         ),         Expanded(           child: Stack(             children: &lt;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: () => null,                     ),                   ),                 ),               ),             ],           ),         ),       ],     );   } }  class HeaderWidget extends StatelessWidget {   const HeaderWidget({     Key? key,   }) : super(key: key);    @override   Widget build(BuildContext context) {     return Center(       child: Text(         'Speech recognition available',         style: TextStyle(fontSize: 22.0),       ),     );   } }  \/\/\/ Display the current error status from the speech \/\/\/ recognizer class ErrorWidget extends StatelessWidget {   const ErrorWidget({     Key? key,     required this.lastError,   }) : super(key: key);    final String lastError;    @override   Widget build(BuildContext context) {     return Column(       children: &lt;Widget>[         Center(           child: Text(             'Error Status',             style: TextStyle(fontSize: 22.0),           ),         ),         Center(           child: Text(lastError),         ),       ],     );   } }  \/\/\/ Controls to start and stop speech recognition class SpeechControlWidget extends StatelessWidget {   const SpeechControlWidget(this.hasSpeech, this.isListening,       this.startListening, this.stopListening, this.cancelListening,       {Key? key})       : super(key: key);    final bool hasSpeech;   final bool isListening;   final void Function() startListening;   final void Function() stopListening;   final void Function() cancelListening;    @override   Widget build(BuildContext context) {     return Row(       mainAxisAlignment: MainAxisAlignment.spaceAround,       children: &lt;Widget>[         TextButton(           onPressed: !hasSpeech || isListening ? null : startListening,           child: Text('Start'),         ),         TextButton(           onPressed: isListening ? stopListening : null,           child: Text('Stop'),         ),         TextButton(           onPressed: isListening ? cancelListening : null,           child: Text('Cancel'),         )       ],     );   } }  class SessionOptionsWidget extends StatelessWidget {   const SessionOptionsWidget(this.currentLocaleId, this.switchLang,       this.localeNames,<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-332864","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/332864","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=332864"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/332864\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=332864"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=332864"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=332864"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}