voicevox_core 0.3.0 copy "voicevox_core: ^0.3.0" to clipboard
voicevox_core: ^0.3.0 copied to clipboard

A Dart library for accessing common Voicevox Core APIs using, FFI.

example/main.dart

// https://github.com/VOICEVOX/voicevox_core/blob/main/example/cpp/unix/talk.cpp
import 'dart:ffi';
import 'dart:io';
import 'package:voicevox_core/voicevox_core.dart';

const gOpenJtalkDicPath = 'assets/open_jtalk_dic_utf_8-1.11';
const gModelFilePath = 'assets/model/0.vvm';
const gText = 'こんにちは、ヴォイスヴォックスのダートバインディングを使っています。';
const gStyleId = 0;
const gOutputWavFilePath = 'talk.wav';

int main() {
  var voicevoxResult = VOICEVOX_RESULT_OK;
  Pointer<VoicevoxOnnxruntime> onnxruntime = nullptr;
  Pointer<OpenJtalkRc> openJtalk = nullptr;
  Pointer<VoicevoxSynthesizer> synthesizer = nullptr;
  Pointer<VoicevoxVoiceModelFile> model = nullptr;
  Pointer<Uint8> wav = nullptr;
  var wavLength = 0;
  if (voicevoxResult == VOICEVOX_RESULT_OK) {
    final rec = voicevoxxOnnxruntimeLoadOnce(
      voicevoxMakeDefaultLoadOnnxruntimeOptions(),
    );
    voicevoxResult = rec.result;
    onnxruntime = rec.onnxruntime;
  }
  if (voicevoxResult == VOICEVOX_RESULT_OK) {
    final rec = voicevoxxOpenJtalkRcNew(gOpenJtalkDicPath);
    voicevoxResult = rec.result;
    openJtalk = rec.openJtalk;
  }
  if (voicevoxResult == VOICEVOX_RESULT_OK) {
    final rec = voicevoxxSynthesizerNew(
      onnxruntime,
      openJtalk,
      voicevoxMakeDefaultInitializeOptions(),
    );
    voicevoxResult = rec.result;
    synthesizer = rec.synthesizer;
  }
  if (voicevoxResult == VOICEVOX_RESULT_OK) {
    final rec = voicevoxxVoiceModelFileOpen(gModelFilePath);
    voicevoxResult = rec.result;
    model = rec.model;
  }
  if (voicevoxResult == VOICEVOX_RESULT_OK) {
    voicevoxResult = voicevoxSynthesizerLoadVoiceModel(synthesizer, model);
  }
  if (voicevoxResult == VOICEVOX_RESULT_OK) {
    final rec = voicevoxxSynthesizerTts(
      synthesizer,
      gText,
      gStyleId,
      voicevoxMakeDefaultTtsOptions(),
    );
    voicevoxResult = rec.result;
    wav = rec.wav;
    wavLength = rec.wavLength;
  }
  if (voicevoxResult == VOICEVOX_RESULT_OK) {
    final _ = File(gOutputWavFilePath)
      ..writeAsBytesSync(wav.asTypedList(wavLength));
  }
  voicevoxWavFree(wav);
  voicevoxVoiceModelFileDelete(model);
  voicevoxSynthesizerDelete(synthesizer);
  voicevoxOpenJtalkRcDelete(openJtalk);
  return 0;
}
0
likes
160
points
82
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Dart library for accessing common Voicevox Core APIs using, FFI.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

ffi

More

Packages that depend on voicevox_core