搜索插件、代码仓与 APP 分类

插件详情v4.2.0

deepgram_speech_to_text

一个适用于 Dart 和 Flutter 的 Deepgram 客户端,支持所有平台上的语音转文本和文本转语音功能。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
8630
喜欢数
52
Pub 分数
140

安装插件

flutter pub add deepgram_speech_to_text

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个用于 Deepgram 的语音转文本和文本转语音 API 的 Dart 和 Flutter 客户端,可在 Android、iOS、Web、macOS、Windows 和 Linux 上实现实时和批量转录。它支持流式音频输入、可自定义的转录设置,并可与语音助手集成。该包简化了在跨平台应用中访问高级语音识别和合成功能的过程。

适合场景

  • 实时语音转录
  • 语音助手集成
  • 录音音频的转录
  • 多语言语音处理
  • 实时字幕
  • 音频内容索引

主要特点

  • 跨平台支持
  • 流式音频转录
  • 可自定义的转录参数
  • 与 Deepgram 的 AI 模型集成
  • 对多种语言的支持
  • 文本转语音功能

适合对象

  • 开发语音功能应用的开发者
  • 需要准确语音识别的应用程序
  • 跨平台音频处理
  • 需要实时转录的应用程序
  • 集成AI驱动的语音服务

使用建议

  • 需要 Deepgram API 密钥
  • 依赖网络连接
  • 可能会产生基于使用的费用
  • 有限的离线功能
  • 平台特定权限需要

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Deepgram Dart

Pub Version Pub Likes Pub Monthly Downloads

ko-fi

A Deepgram client for Dart and Flutter, supporting all Speech-to-Text and Text-to-Speech features on every platform.

Feel free to create issues, contribute to this project or to ask for new features on GitHub !

Features

Speech-to-Text Status Methods
From File ✅ listen.file(), listen.path()
From URL ✅ listen.url()
From Byte ✅ listen.bytes()
From Audio Stream ✅ listen.live(), listen.liveListener()
Text-to-Speech Status Methods
From Text ✅ speak.text()
From Text Stream ✅ speak.live(), speak.liveSpeaker()
Agent Interaction Status Methods
Agent Interaction 🚧 agent.live()

PRs are welcome for all work-in-progress 🚧 features

Getting started

All you need is a Deepgram API key. You can get a free one by signing up on Deepgram

Usage

First create the client with your api key.

Deepgram deepgram = Deepgram('your_api_key');

Pre-recorded

Then you can call the methods you need under the propper listen or speak subclass:

// Speech to text
DeepgramListenResult res = await deepgram.listen.file(File('audio.wav'), queryParams: {
  'model': 'nova-2-general',
  'detect_language': true,
  'filler_words': false,
  'punctuate': true,
  // options here : https://developers.deepgram.com/reference/listen-file
});

// Text to speech
DeepgramSpeakResult res = await deepgram.speak.text('Hello world', queryParams: {
  'model': 'aura-asteria-en'
  // options here : https://developers.deepgram.com/reference/text-to-speech-api
});

Streaming

Speech to text

let's say from a microphone :

//  https://pub.dev/packages/record (other packages would work too)
Stream<List<int>> micStream = await AudioRecorder().startStream(RecordConfig(
      encoder: AudioEncoder.pcm16bits,
      sampleRate: 16000,
      numChannels: 1,
));

final sttStreamParams = {
  'detect_language': false, // not supported by streaming API
  'language': 'en',
  // must specify encoding and sample_rate according to the audio stream
  'encoding': 'linear16',
  'sample_rate': 16000,
};

then you got 2 options depending if you want to have more control over the stream or not :

// 1. you want the stream to manage itself automatically
Stream<DeepgramListenResult> stream = deepgram.listen.live(micStream, queryParams: sttStreamParams);

// 2. you want to manage the stream manually
DeepgramLiveListener listener = deepgram.liveListener(micStream, queryParams: sttStreamParams);
listener.stream.listen((res) {
    print(res.transcript);
});
// connect to the servers and start sending data
listener.start();

// you can pause and resume the transcription (stop sending audio data to the server)
listener.pause(); 
// ...
listener.resume();

// then close the stream when you're done, you can call start() again if you want to restart a transcription 
listener.close(); 
Text to speech
final ttsStreamParams = {
  'model': 'aura-asteria-en',
  'encoding': "linear16",
  'sample_rate': 16000,
// options here: https://developers.deepgram.com/reference/text-to-speech-api
};

then again you got 2 options:

final textStream = ...
// 1. you want the stream to manage itself automatically
Stream<DeepgramSpeakResult> stream = deepgram.speak.live(textStream, queryParams: ttsStreamParams);

// 2. you want to manage the stream manually
DeepgramLiveSpeaker speaker = deepgram.liveListener(textStream, queryParams: ttsStreamParams);
speaker.stream.listen((res) {
    print(res);
    // if you want to use the audio, simplest way is to use Deepgram.toWav(res.data) !
});

// start sending data to the servers
speaker.start();

// https://developers.deepgram.com/docs/tts-ws-flush 
speaker.flush();

//https://developers.deepgram.com/docs/tts-ws-clear
speaker.clear();

// then close the stream when you're done, you can call start() again if you want to restart a transcription 
speaker.close(); 

For more detailed usage check the /example tab

Tested on Android and iOS, but should work on other platforms too.

Debugging common errors

  • make sure your API key is valid and has enough credits
deepgram.isApiKeyValid()
  • "Websocket was not promoted ..." : you are probably using wrong parameters, for example trying to use a whisper model with live streaming (not supported by deepgram)
  • empty transcript/only metadata : if streaming check that you specified encoding and sample_rate properly and that it matches the audio stream
  • double check the parameters you are using, some are not supported for streaming or for some models

Additional information

I created this package for my own needs since there are no dart sdk for deepgram. Happy to share !

Don't hesitate to ask for new features or to contribute on GitHub !

Support

If you'd like to support this project, consider contributing here. Thank you! :)

所属分类

依赖

依赖清单 4 项

源码仓库

使用此插件的项目