패키지, 저장소 및 앱 카테고리 검색

패키지 상세v4.2.5

flutter_tts

텍스트 음성 변환을 위한 플러터 플러그인입니다. 이 플러그인은 iOS, macOS, Android, 웹 및 Windows에서 지원됩니다.

AndroidiOSWebmacOSWindows
30일 다운로드
72.1만
좋아요
1.6천
Pub 점수
150

패키지 설치

flutter pub add flutter_tts

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Flutter TTS는 Flutter 애플리케이션에서 텍스트 음성 변환 기능을 가능하게 하는 크로스 플랫폼 플러그인입니다. Android, iOS, Web, macOS, Windows 등 여러 플랫폼을 지원하여 개발자가 앱에 음성 출력을 원활하게 통합할 수 있도록 합니다. 간단한 API를 제공하여 텍스트를 말하는 오디오로 변환할 수 있으며, 접근성 기능, 음성 보조 도구, 상호작용 학습 도구에 적합합니다. 각 플랫폼의 네이티브 음성 합성 엔진을 활용하여 신뢰할 수 있는 성능과 자연스러운 목소리를 제공합니다.

사용 사례

  • 접근성 기능
  • 음성 안내 내비게이션
  • 교육 앱
  • 인터랙티브 챗봇
  • 오디오 피드백 시스템

주요 기능

  • 크로스 플랫폼 지원
  • 간단한 API 통합
  • 내장 음성 엔진 사용
  • 사용자 정의 가능한 음성 파라미터
  • 실시간 텍스트 재생

적합한 대상

  • 접근성 있는 앱을 개발하는 개발자
  • 교육 소프트웨어 제작자
  • 음성 보조 기능 통합
  • 음성 피드백이 필요한 앱

고려 사항

  • 모바일에서 플랫폼별 권한이 필요합니다
  • 음성 사용 가능 여부는 기기마다 다릅니다
  • 웹에서의 사용자 정의가 제한적
  • 성능은 네이티브 엔진에 따라 달라집니다
  • iOS 및 Android에서 사용자 권한이 필요할 수 있습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Text To Speech

pub package

A flutter text to speech plugin (Swift,Kotlin)

Features

  • [x] Android, iOS, Web, Windows & macOS
    • [x] speak
    • [x] stop
    • [x] get languages
    • [x] set language
    • [x] set speech rate
    • [x] set speech volume
    • [x] set speech pitch
    • [x] get voices
    • [x] set voice
  • [x] Android, iOS, Web & macOS
    • [x] is language available
  • [x] Android, iOS, Web
    • [x] speech marks (requires iOS 7+, Android 26+, and default voice engine for web)
  • [x] Android, iOS
    • [x] synthesize to file (requires iOS 13+)
  • [x] Android, iOS, Web, & Windows
    • [x] pause
  • [x] Android
    • [x] set silence
    • [x] is language installed
    • [x] are languages installed
    • [x] get engines
    • [x] set engine
    • [x] get default engine
    • [x] get default voice
    • [x] set queue mode
    • [x] get max speech input length
  • [x] iOS
    • [x] set shared instance
    • [x] set audio session category

Usage

macOS

OSX version: 10.15

Example App from the macOS_app branch

Web

Website from the example directory.

Progress updates on Web

Progress updates are only supported for native speech synsthesis. Use the default engine to ensure support for progress updates. Chromium#41195426

Android

Change the minimum Android sdk version to 21 (or higher) in your android/app/build.gradle file.

minSdkVersion 21

Update the Kotlin Gradle Plugin Version

Change the verision of the Kotlin Gradle plugin to 1.9.10.
If your project was created with a version of Flutter before 3.19, go to the android/build.gradle file and update the ext.kotlin_version:

ext.kotlin_version = '1.9.10'

Otherwise go to android/settings.gradle and update the verion of the plugin org.jetbrains.kotlin.android:

id "org.jetbrains.kotlin.android" version "1.9.10" apply false

Apps targeting Android 11 that use text-to-speech should declare TextToSpeech.Engine.INTENT_ACTION_TTS_SERVICE in the queries elements of their manifest.

<queries>
  <intent>
    <action android:name="android.intent.action.TTS_SERVICE" />
  </intent>
</queries>
Pausing on Android

Android TTS does not support the pause function natively, so we have implemented a work around. We utilize the native onRangeStart() method to determine the index of start when pause is invoked. We use that index to create a new text the next time speak is invoked. Due to using onRangeStart(), pause works on SDK versions >= 26. Also, if using start and end offsets inside of setProgressHandler(), you'll need to keep a track of them if using pause since they will update once the new text is created when speak is called after being paused.

await flutterTts.pause()

iOS

There's a known issue with integrating plugins that use Swift into a Flutter project created with the Objective-C template. Flutter#16049

Example

To use this plugin :

  dependencies:
    flutter:
      sdk: flutter
    flutter_tts:
  • instantiate FlutterTts
FlutterTts flutterTts = FlutterTts();

To set shared audio instance (iOS only):

await flutterTts.setSharedInstance(true);

To set audio category and options with optional mode (iOS only). The following setup allows background music and in-app audio session to continue simultaneously:

await flutterTts.setIosAudioCategory(IosTextToSpeechAudioCategory.ambient,
     [
          IosTextToSpeechAudioCategoryOptions.allowBluetooth,
          IosTextToSpeechAudioCategoryOptions.allowBluetoothA2DP,
          IosTextToSpeechAudioCategoryOptions.mixWithOthers
     ],
     IosTextToSpeechAudioMode.voicePrompt
);

To await speak completion.

await flutterTts.awaitSpeakCompletion(true);

To await synthesize to file completion.

await flutterTts.awaitSynthCompletion(true);
speak, stop, getLanguages, setLanguage, setSpeechRate, getVoices, setVoice, setVolume, setPitch, isLanguageAvailable, setSharedInstance
Future _speak() async{
    var result = await flutterTts.speak("Hello World");
    if (result == 1) setState(() => ttsState = TtsState.playing);
}

Future _stop() async{
    var result = await flutterTts.stop();
    if (result == 1) setState(() => ttsState = TtsState.stopped);
}

List<dynamic> languages = await flutterTts.getLanguages;

await flutterTts.setLanguage("en-US");

await flutterTts.setSpeechRate(1.0);

await flutterTts.setVolume(1.0);

await flutterTts.setPitch(1.0);

await flutterTts.isLanguageAvailable("en-US");

// iOS, Android and Web only
//see the "Pausing on Android" section for more info
await flutterTts.pause();

// iOS, macOS, and Android only
// The last parameter is an optional boolean value for isFullPath (defaults to false)
await flutterTts.synthesizeToFile("Hello World", Platform.isAndroid ? "tts.wav" : "tts.caf", false);

// Each voice is a Map containing at least these keys: name, locale
// - Windows (UWP voices) only: gender, identifier
// - iOS, macOS only: quality, gender, identifier
// - Android only: quality, latency, network_required, features 
List<Map> voices = await flutterTts.getVoices;

await flutterTts.setVoice({"name": "Karen", "locale": "en-AU"});
// iOS, macOS only
await flutterTts.setVoice({"identifier": "com.apple.voice.compact.en-AU.Karen"});

// iOS only
await flutterTts.setSharedInstance(true);

// Android only
await flutterTts.speak("Hello World", focus: true);

await flutterTts.setSilence(2);

await flutterTts.getEngines;

await flutterTts.getDefaultVoice;

await flutterTts.isLanguageInstalled("en-AU");

await flutterTts.areLanguagesInstalled(["en-AU", "en-US"]);

await flutterTts.setQueueMode(1);

await flutterTts.getMaxSpeechInputLength;

await flutterTts.setAudioAttributesForNavigation();
Listening for platform calls
flutterTts.setStartHandler(() {
  setState(() {
    ttsState = TtsState.playing;
  });
});

flutterTts.setCompletionHandler(() {
  setState(() {
    ttsState = TtsState.stopped;
  });
});

flutterTts.setProgressHandler((String text, int startOffset, int endOffset, String word) {
  setState(() {
    _currentWord = word;
  });
});

flutterTts.setErrorHandler((msg) {
  setState(() {
    ttsState = TtsState.stopped;
  });
});

flutterTts.setCancelHandler((msg) {
  setState(() {
    ttsState = TtsState.stopped;
  });
});

// Android, iOS and Web
flutterTts.setPauseHandler((msg) {
  setState(() {
    ttsState = TtsState.paused;
  });
});

flutterTts.setContinueHandler((msg) {
  setState(() {
    ttsState = TtsState.continued;
  });
});

Getting Started

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트