Dart:tml和Dart:js未找到错误Flutter。

3

我正在尝试在我的聊天应用程序中添加语音消息的文字转语音和语音转文字功能。我完全按照这份文档进行操作:https://pub.dev/packages/flutter_tts/example。但是我不得不导入另一个名为flutter_tts_web.dart的库。我认为这不会成为一个大问题,但它似乎引起了一个错误。以下是堆栈跟踪信息:

../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/flutter_tts-1.2.6/lib/flutter_tts_web.dart:2:8: Error: Not found: 'dart:html'
import 'dart:html' as html;
       ^
../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/flutter_tts-1.2.6/lib/flutter_tts_web.dart:3:8: Error: Not found: 'dart:js'
import 'dart:js';
       ^
../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/flutter_tts-1.2.6/lib/flutter_tts_web.dart:31:3: Error: Type 'html.SpeechSynthesis' not found.
  html.SpeechSynthesis synth;
  ^^^^^^^^^^^^^^^^^^^^
../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/flutter_tts-1.2.6/lib/flutter_tts_web.dart:32:3: Error: Type 'html.SpeechSynthesisUtterance' not found.
  html.SpeechSynthesisUtterance utterance;
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/flutter_tts-1.2.6/lib/flutter_tts_web.dart:31:8: Error: 'SpeechSynthesis' isn't a type.
  html.SpeechSynthesis synth;
       ^^^^^^^^^^^^^^^
../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/flutter_tts-1.2.6/lib/flutter_tts_web.dart:32:8: Error: 'SpeechSynthesisUtterance' isn't a type.
  html.SpeechSynthesisUtterance utterance;
       ^^^^^^^^^^^^^^^^^^^^^^^^
../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/flutter_tts-1.2.6/lib/flutter_tts_web.dart:37:17: Error: Method not found: 'SpeechSynthesisUtterance'.
    utterance = html.SpeechSynthesisUtterance();
                ^^^^^^^^^^^^^^^^^^^^^^^^
../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/flutter_tts-1.2.6/lib/flutter_tts_web.dart:38:18: Error: Getter not found: 'window'.
    synth = html.window.speechSynthesis;
                 ^^^^^^
../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/flutter_tts-1.2.6/lib/flutter_tts_web.dart:156:63: Error: 'JsArray' isn't a type.
        context['speechSynthesis'].callMethod('getVoices') as JsArray<dynamic>;
                                                              ^^^^^^^
../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/flutter_tts-1.2.6/lib/flutter_tts_web.dart:156:9: Error: The getter 'context' isn't defined for the class 'FlutterTtsPlugin'.
 - 'FlutterTtsPlugin' is from 'package:flutter_tts/flutter_tts_web.dart' ('../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/flutter_tts-1.2.6/lib/flutter_tts_web.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'context'.
        context['speechSynthesis'].callMethod('getVoices') as JsArray<dynamic>;
        ^^^^^^^
/C:/flutter/packages/flutter_web_plugins/lib/src/plugin_registry.dart:29:5: Error: Method not found: 'webOnlySetPluginHandler'.
    ui.webOnlySetPluginHandler(_binaryMessenger.handlePlatformMessage);
    ^^^^^^^^^^^^^^^^^^^^^^^
Unhandled exception:
FileSystemException(uri=
org-dartlang-untranslatable-uri:dart%3Ahtml; message=StandardFileSystem only supports file:* and data:* URIs)
#0      StandardFileSystem.entityForUri (package:front_end/src/api_proto
type/standard_file_system.dart:33:7)
#1      asFileUri (package:vm/kernel_front_end.dart:659:37)
#2      writeDepfile (package:vm/kernel_front_end.dart:853:21)
<asynchronous suspension>
#3      FrontendCompiler.compile (package:frontend_server/frontend_server.dart:574:15)
<asynchronous suspension>
#4      _FlutterFrontendCompiler.compile (package:flutter_frontend_server/server.dart:43:22)
#5      starter (package:flutter_frontend_server/server.dart:182:27)
#6      main (file:///C:/b/s/w/ir/cache/builder/src/flutter/flutter_frontend_server/bin/starter.dart:9:30)
#7      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32)
#8      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)



FAILURE: Build failed with an exception.

* Where:
Script 'C:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 896

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 38s
Exception: Gradle task assembleDebug failed with exit code 1

我试图删除这个文件,但变量Tts State依赖于网络文件。我也尝试过flutter clean和切换到beta通道。请尽快帮助我,因为这是一个黑客马拉松比赛,我只剩下8个小时了。我几乎可以立即提供任何必要的代码。


我认为你需要使用稳定通道。 - Lapa Ny Aina Tanjona
@LapaNyAinaTanjona 没有起作用。同样的错误。 - Siddharth Agrawal
你解决了吗?我这里也遇到了同样的问题。 - Hyung Tae Carapeto Figur
@HyungTaeCarapetoFigur,还有另一个文本转语音插件,它完美地工作。它具有相同的功能,但提供它们的方式不同,而且文档不是很好。 - Siddharth Agrawal
@SiddharthAgrawal 谢谢你让我知道。但是我已经成功了。一开始我尝试按照文档逐步自己完成,但出现了错误。但是当我只是复制并粘贴他们的Flutter项目示例时,它就可以工作了。然后我开始修改它以适应我的项目。 - Hyung Tae Carapeto Figur
1个回答

0

我认为这是因为Dart没有安装,确保你已经正确地安装了Dart,并在安装Dart后使用以下命令。

pub get

2
我尝试了一下,但它并没有起作用。现在我正在使用一个功能较少的单独库,因为我没有时间。 - Siddharth Agrawal

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接