Add TTS functionality to Dart console app - dart

can I get some pointers on how to add Text To Speech functionality to a console/CLI app. I have tried packages for Flutter but I get this error 'Error: Not found: 'dart:ui'. I am assuming they expect a user interface.
I am pretty much a novice, would be glad answers do not assume too much on my side. Thanks!

Yes, Flutter is all about UI whereas a command line app has no UI.
They dont have anything to do with eachother except that Dart is the language used by Flutter.
Flutter tts plugins depend on the specific tts implementation embedded in the OS that the plugin will be running on — Android / IOS, etc.
A Dart command line tool runs in a VM and is OS-independent.
So, as far as I know, it is impossible to import a Flutter plugin into a Dart command line app and then compile it.
The only way I can see to get tts functionality in a Dart command line tool is to use a web based (OS-independent) tts service such as the Google text to speech API.

Related

How can I add iOS support via dart ffi without adding flutter sdk as a dependency?

I am working on the dart_ping package and although it currently is tagged with iOS support, it does not actually support iOS. This is due to the way pub.dev detects supported platforms. I have filed an issue on dart-sdk repo.
Nonetheless, I would like to add iOS support while still preserving support for dart native. Right now, dart_ping works by calling the host OS's ping binary. The ping binary is available on Windows, macOS, Linux, and Android but not on iOS.
Current methods of performing a ping on iOS use native Objective-C code and call them via either method channels or ffi. Since method channels are a flutter feature rather than a dart feature, using them would require dart_ping to depend on the flutter sdk, which would prevent it from being used in a dart native application (perhaps server side).
Ffi on the other hand, is a dart native feature and is capable of doing what I want. However, I cannot seem to find a way to include the iOS framework/library/binary for ping in my dart_ping package in a way that instructs a flutter application to include it and link it to the iOS target/runner.
Is there any way to keep dart native support in my package while also supporting the edge case of iOS needing an extra non-dart framework? Even federated plugins depend on the flutter sdk. It seems to me that we need a pure dart equivalent to the federated plugin system.
TLDR: How do I add a pre-compiled iOS framework or binary to a dart package without depending on the flutter sdk and call it only when the package is used on iOS ?
For your specific case of adding iOS support only for Flutter users of your package but keeping the package as pure Dart without a dependency on the Flutter SDK should be possible by having a Flutter plugin package that depends on your Dart package.
In the pure Dart package you can have FFI calls to a native iOS library, but its actually the Flutter plugin package that supplies the native iOS library per the Flutter documentation for using FFI.
You would of course need to make it very clear in the documentation for your pure Dart package that for iOS, it should only be used via the "wrapper" plugin package.
Unfortunately this is a rather convoluted way to do it, but I don't know of a better way to achieve this as of now.
There is further discussion on this topic in the comments in this issue, which as of today is still open.

Why Flutter copies the src of standard libraries to sky_engine?

Since dart:ffi is available from Dart 2.2.0-dev.2.0, I've been trying to use that library. The sample app works fine for me and I also tried to use it for my Flutter app but I couldn't call it with import "dart:ffi", although Flutter on my machine was HEAD of master that used Dart 2.3.0-dev.0.0.
I checked what happened, then I found that sky_engine didn't contain ffi.dart while it contained other libraries (e.g. "dart:core"). Also I noticed that the source files of those libraries were copied from $FLUTTER_ROOT/bin/cache/dart-sdk/lib to $FLUTTER_ROOT/bin/cache/pkg/sky_engine using BUILD.gn or _embedder.yaml and that seemed to be why I couldn't use the dart:ffi in my Flutter app.
However, in the first place, why does Flutter need sky_engine, which is "the interface between Dart and the Flutter Engine"? Why not calling them directly without this glue code?
Flutter has a good documentation for FFI to be able to call native C APIs. Adding import 'dart:ffi' as ffi; on the Flutter app works without issues as of my testing with Flutter 2.5. If you're able to provide a minimal repro of your issue, this will help folks to understand the question better.
As for the question on why sky_engine is used by Flutter, that's just simply because it's the "flutter_engine" - similar to what has been already mentioned in the comments.

Using full Dart SDK with Flutter

Is there any way to tell Flutter use more newer dart sdk version? I found it a bit tricky, because it checks some hashes in flutter/bin/cache/*.stamp. And when I'm trying to make a symbolic link to homebrew installed dart sdk it cannot build flutter_tool. To do that I've removed flutter_tool.stamp and flutter_tool.snapshot files. Something else needed?
I'm not actually sure if it is a need or not, but these tools are still in beta, for me it sounds logic to use edge versions.
Flutter ships with a customized Dart SDK (for example with the web parts stripped).
The Flutter SDK is tightly bound to a specific Dart SDK version and there is no reliable way to make Flutter work with any other Dart SDK than the one it is installed with.

using import 'dart:html' in flutter - Do I need additional dependencies?

I came across a websocket example that I would like to use. However it uses import 'dart:html';. When I introduce that in my Flutter project seems like its not being picked up. Do I need to add additional dependencies to the pubspec.yaml?
dart:html can't be used in Flutter.
It is for browser applications only.
dart:html also only comes with the regular Dart SDK, not with the Dart SDK shipped with Flutter.
I know this is an old question but let me drop this answer here.
I've searched for a web crawler/scraper for Flutter for a while now. I've tried to use FlutterWebview and also the HTML package but no way. Recently I've found a new package for this.
The advantage of this package is that it is really cross platform as explained:
Cross-platform dart:html that works in the browser, Dart VM, and Flutter.
Typical use cases are:
Cross-platform application development (e.g. Flutter mobile and web versions).
Web crawling and scraping
you can use universal_html for any scraping/crawling purpose
Since the merge of Flutter-web into the main Flutter repository, it's no longer possible to directly add imports for web libraries (e.g. dart:html) in a Flutter project on the main channel when targeting Web, Android and iOS.
Use the universal html package which provides extensive support for multiple platforms and web libraries.
From the root level of your project, command
1.
flutter pub add universal_html
2. import 'package:universal_html/html.dart' as html
This package isn't required to run some web files (e.g. dart:js). In my case, I just had to remove the import 'dart:js' import statement.

Other tran transpiling to JS, does google dart compile to object code?

Google dart compiles to javascript code but dart is also a standalone language. I know Dart can also run without javascript (on the vm), but to what does it compile to? Does it compile to C or object code? I couldnt find any information about it.
Im also asking because dart works on mobile devices and ive also read it will be used in some experimental OS called fuchsia.
As far as I know
it's compiled to binary code on-the-fly in the VM,
it's compiled to binary code ahead of time with AoT.

Resources