feat: publish v1.0.1

Signed-off-by: 小草林(田梓萱) <xcl@xuegao-tzx.top>
This commit is contained in:
2024-06-12 09:52:36 +08:00
parent 2e87763b84
commit af91fc48cb
157 changed files with 180217 additions and 0 deletions

2
lib/bean/_models.dart Normal file
View File

@@ -0,0 +1,2 @@
export "./request_bean.dart";
export "./response_bean.dart";

109
lib/bean/request_bean.dart Normal file
View File

@@ -0,0 +1,109 @@
/*
* Copyright (c) 田梓萱[小草林] 2021-2024.
* All Rights Reserved.
* All codes are protected by China's regulations on the protection of computer software, and infringement must be investigated.
* 版权所有 (c) 田梓萱[小草林] 2021-2024.
* 所有代码均受中国《计算机软件保护条例》保护,侵权必究.
*/
import "dart:convert";
import "package:freezed_annotation/freezed_annotation.dart";
import "package:whisper_flutter_new/bean/whisper_dto.dart";
part "request_bean.freezed.dart";
part "request_bean.g.dart";
@unfreezed
class TranscribeRequest with _$TranscribeRequest {
factory TranscribeRequest({
required String audio,
@Default(false) bool isTranslate,
@Default(6) int threads,
@Default(false) bool isVerbose,
@Default("auto") String language,
@Default(false) bool isSpecialTokens,
@Default(false) bool isNoTimestamps,
@Default(1) int nProcessors,
@Default(false) bool splitOnWord,
@Default(false) bool noFallback,
@Default(false) bool diarize,
@Default(false) bool speedUp,
}) = _TranscribeRequest;
factory TranscribeRequest.fromJson(Map<String, dynamic> json) =>
_$TranscribeRequestFromJson(json);
}
@freezed
class TranscribeRequestDto
with _$TranscribeRequestDto
implements WhisperRequestDto {
const factory TranscribeRequestDto({
required String audio,
required String model,
@JsonKey(name: "is_translate") required bool isTranslate,
required int threads,
@JsonKey(name: "is_verbose") required bool isVerbose,
required String language,
@JsonKey(name: "is_special_tokens") required bool isSpecialTokens,
@JsonKey(name: "is_no_timestamps") required bool isNoTimestamps,
@JsonKey(name: "n_processors") required int nProcessors,
@JsonKey(name: "split_on_word") required bool splitOnWord,
@JsonKey(name: "no_fallback") required bool noFallback,
required bool diarize,
@JsonKey(name: "speed_up") required bool speedUp,
}) = _TranscribeRequestDto;
/// Convert [request] to TranscribeRequestDto with specified [modelPath]
factory TranscribeRequestDto.fromTranscribeRequest(
TranscribeRequest request,
String modelPath,
) {
return TranscribeRequestDto(
audio: request.audio,
model: modelPath,
isTranslate: request.isTranslate,
threads: request.threads,
isVerbose: request.isVerbose,
language: request.language,
isSpecialTokens: request.isSpecialTokens,
isNoTimestamps: request.isNoTimestamps,
nProcessors: request.nProcessors,
splitOnWord: request.splitOnWord,
noFallback: request.noFallback,
diarize: request.diarize,
speedUp: request.speedUp,
);
}
const TranscribeRequestDto._();
/// Create request json
factory TranscribeRequestDto.fromJson(Map<String, dynamic> json) =>
_$TranscribeRequestDtoFromJson(json);
@override
String get specialType => "getTextFromWavFile";
@override
String toRequestString() {
return json.encode({
"@type": specialType,
...toJson(),
});
}
}
@freezed
class VersionRequest with _$VersionRequest implements WhisperRequestDto {
const factory VersionRequest() = _VersionRequest;
const VersionRequest._();
@override
String get specialType => "getVersion";
@override
String toRequestString() {
return json.encode({
"@type": specialType,
});
}
}

View File

@@ -0,0 +1,882 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'request_bean.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
TranscribeRequest _$TranscribeRequestFromJson(Map<String, dynamic> json) {
return _TranscribeRequest.fromJson(json);
}
/// @nodoc
mixin _$TranscribeRequest {
String get audio => throw _privateConstructorUsedError;
set audio(String value) => throw _privateConstructorUsedError;
bool get isTranslate => throw _privateConstructorUsedError;
set isTranslate(bool value) => throw _privateConstructorUsedError;
int get threads => throw _privateConstructorUsedError;
set threads(int value) => throw _privateConstructorUsedError;
bool get isVerbose => throw _privateConstructorUsedError;
set isVerbose(bool value) => throw _privateConstructorUsedError;
String get language => throw _privateConstructorUsedError;
set language(String value) => throw _privateConstructorUsedError;
bool get isSpecialTokens => throw _privateConstructorUsedError;
set isSpecialTokens(bool value) => throw _privateConstructorUsedError;
bool get isNoTimestamps => throw _privateConstructorUsedError;
set isNoTimestamps(bool value) => throw _privateConstructorUsedError;
int get nProcessors => throw _privateConstructorUsedError;
set nProcessors(int value) => throw _privateConstructorUsedError;
bool get splitOnWord => throw _privateConstructorUsedError;
set splitOnWord(bool value) => throw _privateConstructorUsedError;
bool get noFallback => throw _privateConstructorUsedError;
set noFallback(bool value) => throw _privateConstructorUsedError;
bool get diarize => throw _privateConstructorUsedError;
set diarize(bool value) => throw _privateConstructorUsedError;
bool get speedUp => throw _privateConstructorUsedError;
set speedUp(bool value) => throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$TranscribeRequestCopyWith<TranscribeRequest> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $TranscribeRequestCopyWith<$Res> {
factory $TranscribeRequestCopyWith(
TranscribeRequest value, $Res Function(TranscribeRequest) then) =
_$TranscribeRequestCopyWithImpl<$Res, TranscribeRequest>;
@useResult
$Res call(
{String audio,
bool isTranslate,
int threads,
bool isVerbose,
String language,
bool isSpecialTokens,
bool isNoTimestamps,
int nProcessors,
bool splitOnWord,
bool noFallback,
bool diarize,
bool speedUp});
}
/// @nodoc
class _$TranscribeRequestCopyWithImpl<$Res, $Val extends TranscribeRequest>
implements $TranscribeRequestCopyWith<$Res> {
_$TranscribeRequestCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
@pragma('vm:prefer-inline')
@override
$Res call({
Object? audio = null,
Object? isTranslate = null,
Object? threads = null,
Object? isVerbose = null,
Object? language = null,
Object? isSpecialTokens = null,
Object? isNoTimestamps = null,
Object? nProcessors = null,
Object? splitOnWord = null,
Object? noFallback = null,
Object? diarize = null,
Object? speedUp = null,
}) {
return _then(_value.copyWith(
audio: null == audio
? _value.audio
: audio // ignore: cast_nullable_to_non_nullable
as String,
isTranslate: null == isTranslate
? _value.isTranslate
: isTranslate // ignore: cast_nullable_to_non_nullable
as bool,
threads: null == threads
? _value.threads
: threads // ignore: cast_nullable_to_non_nullable
as int,
isVerbose: null == isVerbose
? _value.isVerbose
: isVerbose // ignore: cast_nullable_to_non_nullable
as bool,
language: null == language
? _value.language
: language // ignore: cast_nullable_to_non_nullable
as String,
isSpecialTokens: null == isSpecialTokens
? _value.isSpecialTokens
: isSpecialTokens // ignore: cast_nullable_to_non_nullable
as bool,
isNoTimestamps: null == isNoTimestamps
? _value.isNoTimestamps
: isNoTimestamps // ignore: cast_nullable_to_non_nullable
as bool,
nProcessors: null == nProcessors
? _value.nProcessors
: nProcessors // ignore: cast_nullable_to_non_nullable
as int,
splitOnWord: null == splitOnWord
? _value.splitOnWord
: splitOnWord // ignore: cast_nullable_to_non_nullable
as bool,
noFallback: null == noFallback
? _value.noFallback
: noFallback // ignore: cast_nullable_to_non_nullable
as bool,
diarize: null == diarize
? _value.diarize
: diarize // ignore: cast_nullable_to_non_nullable
as bool,
speedUp: null == speedUp
? _value.speedUp
: speedUp // ignore: cast_nullable_to_non_nullable
as bool,
) as $Val);
}
}
/// @nodoc
abstract class _$$TranscribeRequestImplCopyWith<$Res>
implements $TranscribeRequestCopyWith<$Res> {
factory _$$TranscribeRequestImplCopyWith(_$TranscribeRequestImpl value,
$Res Function(_$TranscribeRequestImpl) then) =
__$$TranscribeRequestImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{String audio,
bool isTranslate,
int threads,
bool isVerbose,
String language,
bool isSpecialTokens,
bool isNoTimestamps,
int nProcessors,
bool splitOnWord,
bool noFallback,
bool diarize,
bool speedUp});
}
/// @nodoc
class __$$TranscribeRequestImplCopyWithImpl<$Res>
extends _$TranscribeRequestCopyWithImpl<$Res, _$TranscribeRequestImpl>
implements _$$TranscribeRequestImplCopyWith<$Res> {
__$$TranscribeRequestImplCopyWithImpl(_$TranscribeRequestImpl _value,
$Res Function(_$TranscribeRequestImpl) _then)
: super(_value, _then);
@pragma('vm:prefer-inline')
@override
$Res call({
Object? audio = null,
Object? isTranslate = null,
Object? threads = null,
Object? isVerbose = null,
Object? language = null,
Object? isSpecialTokens = null,
Object? isNoTimestamps = null,
Object? nProcessors = null,
Object? splitOnWord = null,
Object? noFallback = null,
Object? diarize = null,
Object? speedUp = null,
}) {
return _then(_$TranscribeRequestImpl(
audio: null == audio
? _value.audio
: audio // ignore: cast_nullable_to_non_nullable
as String,
isTranslate: null == isTranslate
? _value.isTranslate
: isTranslate // ignore: cast_nullable_to_non_nullable
as bool,
threads: null == threads
? _value.threads
: threads // ignore: cast_nullable_to_non_nullable
as int,
isVerbose: null == isVerbose
? _value.isVerbose
: isVerbose // ignore: cast_nullable_to_non_nullable
as bool,
language: null == language
? _value.language
: language // ignore: cast_nullable_to_non_nullable
as String,
isSpecialTokens: null == isSpecialTokens
? _value.isSpecialTokens
: isSpecialTokens // ignore: cast_nullable_to_non_nullable
as bool,
isNoTimestamps: null == isNoTimestamps
? _value.isNoTimestamps
: isNoTimestamps // ignore: cast_nullable_to_non_nullable
as bool,
nProcessors: null == nProcessors
? _value.nProcessors
: nProcessors // ignore: cast_nullable_to_non_nullable
as int,
splitOnWord: null == splitOnWord
? _value.splitOnWord
: splitOnWord // ignore: cast_nullable_to_non_nullable
as bool,
noFallback: null == noFallback
? _value.noFallback
: noFallback // ignore: cast_nullable_to_non_nullable
as bool,
diarize: null == diarize
? _value.diarize
: diarize // ignore: cast_nullable_to_non_nullable
as bool,
speedUp: null == speedUp
? _value.speedUp
: speedUp // ignore: cast_nullable_to_non_nullable
as bool,
));
}
}
/// @nodoc
@JsonSerializable()
class _$TranscribeRequestImpl implements _TranscribeRequest {
_$TranscribeRequestImpl(
{required this.audio,
this.isTranslate = false,
this.threads = 8,
this.isVerbose = false,
this.language = 'auto',
this.isSpecialTokens = false,
this.isNoTimestamps = false,
this.nProcessors = 1,
this.splitOnWord = false,
this.noFallback = false,
this.diarize = false,
this.speedUp = false});
factory _$TranscribeRequestImpl.fromJson(Map<String, dynamic> json) =>
_$$TranscribeRequestImplFromJson(json);
@override
String audio;
@override
@JsonKey()
bool isTranslate;
@override
@JsonKey()
int threads;
@override
@JsonKey()
bool isVerbose;
@override
@JsonKey()
String language;
@override
@JsonKey()
bool isSpecialTokens;
@override
@JsonKey()
bool isNoTimestamps;
@override
@JsonKey()
int nProcessors;
@override
@JsonKey()
bool splitOnWord;
@override
@JsonKey()
bool noFallback;
@override
@JsonKey()
bool diarize;
@override
@JsonKey()
bool speedUp;
@override
String toString() {
return 'TranscribeRequest(audio: $audio, isTranslate: $isTranslate, threads: $threads, isVerbose: $isVerbose, language: $language, isSpecialTokens: $isSpecialTokens, isNoTimestamps: $isNoTimestamps, nProcessors: $nProcessors, splitOnWord: $splitOnWord, noFallback: $noFallback, diarize: $diarize, speedUp: $speedUp)';
}
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$TranscribeRequestImplCopyWith<_$TranscribeRequestImpl> get copyWith =>
__$$TranscribeRequestImplCopyWithImpl<_$TranscribeRequestImpl>(
this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$TranscribeRequestImplToJson(
this,
);
}
}
abstract class _TranscribeRequest implements TranscribeRequest {
factory _TranscribeRequest(
{required String audio,
bool isTranslate,
int threads,
bool isVerbose,
String language,
bool isSpecialTokens,
bool isNoTimestamps,
int nProcessors,
bool splitOnWord,
bool noFallback,
bool diarize,
bool speedUp}) = _$TranscribeRequestImpl;
factory _TranscribeRequest.fromJson(Map<String, dynamic> json) =
_$TranscribeRequestImpl.fromJson;
@override
String get audio;
set audio(String value);
@override
bool get isTranslate;
set isTranslate(bool value);
@override
int get threads;
set threads(int value);
@override
bool get isVerbose;
set isVerbose(bool value);
@override
String get language;
set language(String value);
@override
bool get isSpecialTokens;
set isSpecialTokens(bool value);
@override
bool get isNoTimestamps;
set isNoTimestamps(bool value);
@override
int get nProcessors;
set nProcessors(int value);
@override
bool get splitOnWord;
set splitOnWord(bool value);
@override
bool get noFallback;
set noFallback(bool value);
@override
bool get diarize;
set diarize(bool value);
@override
bool get speedUp;
set speedUp(bool value);
@override
@JsonKey(ignore: true)
_$$TranscribeRequestImplCopyWith<_$TranscribeRequestImpl> get copyWith =>
throw _privateConstructorUsedError;
}
TranscribeRequestDto _$TranscribeRequestDtoFromJson(Map<String, dynamic> json) {
return _TranscribeRequestDto.fromJson(json);
}
/// @nodoc
mixin _$TranscribeRequestDto {
String get audio => throw _privateConstructorUsedError;
String get model => throw _privateConstructorUsedError;
@JsonKey(name: 'is_translate')
bool get isTranslate => throw _privateConstructorUsedError;
int get threads => throw _privateConstructorUsedError;
@JsonKey(name: 'is_verbose')
bool get isVerbose => throw _privateConstructorUsedError;
String get language => throw _privateConstructorUsedError;
@JsonKey(name: 'is_special_tokens')
bool get isSpecialTokens => throw _privateConstructorUsedError;
@JsonKey(name: 'is_no_timestamps')
bool get isNoTimestamps => throw _privateConstructorUsedError;
@JsonKey(name: 'n_processors')
int get nProcessors => throw _privateConstructorUsedError;
@JsonKey(name: 'split_on_word')
bool get splitOnWord => throw _privateConstructorUsedError;
@JsonKey(name: 'no_fallback')
bool get noFallback => throw _privateConstructorUsedError;
bool get diarize => throw _privateConstructorUsedError;
@JsonKey(name: 'speed_up')
bool get speedUp => throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$TranscribeRequestDtoCopyWith<TranscribeRequestDto> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $TranscribeRequestDtoCopyWith<$Res> {
factory $TranscribeRequestDtoCopyWith(TranscribeRequestDto value,
$Res Function(TranscribeRequestDto) then) =
_$TranscribeRequestDtoCopyWithImpl<$Res, TranscribeRequestDto>;
@useResult
$Res call(
{String audio,
String model,
@JsonKey(name: 'is_translate') bool isTranslate,
int threads,
@JsonKey(name: 'is_verbose') bool isVerbose,
String language,
@JsonKey(name: 'is_special_tokens') bool isSpecialTokens,
@JsonKey(name: 'is_no_timestamps') bool isNoTimestamps,
@JsonKey(name: 'n_processors') int nProcessors,
@JsonKey(name: 'split_on_word') bool splitOnWord,
@JsonKey(name: 'no_fallback') bool noFallback,
bool diarize,
@JsonKey(name: 'speed_up') bool speedUp});
}
/// @nodoc
class _$TranscribeRequestDtoCopyWithImpl<$Res,
$Val extends TranscribeRequestDto>
implements $TranscribeRequestDtoCopyWith<$Res> {
_$TranscribeRequestDtoCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
@pragma('vm:prefer-inline')
@override
$Res call({
Object? audio = null,
Object? model = null,
Object? isTranslate = null,
Object? threads = null,
Object? isVerbose = null,
Object? language = null,
Object? isSpecialTokens = null,
Object? isNoTimestamps = null,
Object? nProcessors = null,
Object? splitOnWord = null,
Object? noFallback = null,
Object? diarize = null,
Object? speedUp = null,
}) {
return _then(_value.copyWith(
audio: null == audio
? _value.audio
: audio // ignore: cast_nullable_to_non_nullable
as String,
model: null == model
? _value.model
: model // ignore: cast_nullable_to_non_nullable
as String,
isTranslate: null == isTranslate
? _value.isTranslate
: isTranslate // ignore: cast_nullable_to_non_nullable
as bool,
threads: null == threads
? _value.threads
: threads // ignore: cast_nullable_to_non_nullable
as int,
isVerbose: null == isVerbose
? _value.isVerbose
: isVerbose // ignore: cast_nullable_to_non_nullable
as bool,
language: null == language
? _value.language
: language // ignore: cast_nullable_to_non_nullable
as String,
isSpecialTokens: null == isSpecialTokens
? _value.isSpecialTokens
: isSpecialTokens // ignore: cast_nullable_to_non_nullable
as bool,
isNoTimestamps: null == isNoTimestamps
? _value.isNoTimestamps
: isNoTimestamps // ignore: cast_nullable_to_non_nullable
as bool,
nProcessors: null == nProcessors
? _value.nProcessors
: nProcessors // ignore: cast_nullable_to_non_nullable
as int,
splitOnWord: null == splitOnWord
? _value.splitOnWord
: splitOnWord // ignore: cast_nullable_to_non_nullable
as bool,
noFallback: null == noFallback
? _value.noFallback
: noFallback // ignore: cast_nullable_to_non_nullable
as bool,
diarize: null == diarize
? _value.diarize
: diarize // ignore: cast_nullable_to_non_nullable
as bool,
speedUp: null == speedUp
? _value.speedUp
: speedUp // ignore: cast_nullable_to_non_nullable
as bool,
) as $Val);
}
}
/// @nodoc
abstract class _$$TranscribeRequestDtoImplCopyWith<$Res>
implements $TranscribeRequestDtoCopyWith<$Res> {
factory _$$TranscribeRequestDtoImplCopyWith(_$TranscribeRequestDtoImpl value,
$Res Function(_$TranscribeRequestDtoImpl) then) =
__$$TranscribeRequestDtoImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{String audio,
String model,
@JsonKey(name: 'is_translate') bool isTranslate,
int threads,
@JsonKey(name: 'is_verbose') bool isVerbose,
String language,
@JsonKey(name: 'is_special_tokens') bool isSpecialTokens,
@JsonKey(name: 'is_no_timestamps') bool isNoTimestamps,
@JsonKey(name: 'n_processors') int nProcessors,
@JsonKey(name: 'split_on_word') bool splitOnWord,
@JsonKey(name: 'no_fallback') bool noFallback,
bool diarize,
@JsonKey(name: 'speed_up') bool speedUp});
}
/// @nodoc
class __$$TranscribeRequestDtoImplCopyWithImpl<$Res>
extends _$TranscribeRequestDtoCopyWithImpl<$Res, _$TranscribeRequestDtoImpl>
implements _$$TranscribeRequestDtoImplCopyWith<$Res> {
__$$TranscribeRequestDtoImplCopyWithImpl(_$TranscribeRequestDtoImpl _value,
$Res Function(_$TranscribeRequestDtoImpl) _then)
: super(_value, _then);
@pragma('vm:prefer-inline')
@override
$Res call({
Object? audio = null,
Object? model = null,
Object? isTranslate = null,
Object? threads = null,
Object? isVerbose = null,
Object? language = null,
Object? isSpecialTokens = null,
Object? isNoTimestamps = null,
Object? nProcessors = null,
Object? splitOnWord = null,
Object? noFallback = null,
Object? diarize = null,
Object? speedUp = null,
}) {
return _then(_$TranscribeRequestDtoImpl(
audio: null == audio
? _value.audio
: audio // ignore: cast_nullable_to_non_nullable
as String,
model: null == model
? _value.model
: model // ignore: cast_nullable_to_non_nullable
as String,
isTranslate: null == isTranslate
? _value.isTranslate
: isTranslate // ignore: cast_nullable_to_non_nullable
as bool,
threads: null == threads
? _value.threads
: threads // ignore: cast_nullable_to_non_nullable
as int,
isVerbose: null == isVerbose
? _value.isVerbose
: isVerbose // ignore: cast_nullable_to_non_nullable
as bool,
language: null == language
? _value.language
: language // ignore: cast_nullable_to_non_nullable
as String,
isSpecialTokens: null == isSpecialTokens
? _value.isSpecialTokens
: isSpecialTokens // ignore: cast_nullable_to_non_nullable
as bool,
isNoTimestamps: null == isNoTimestamps
? _value.isNoTimestamps
: isNoTimestamps // ignore: cast_nullable_to_non_nullable
as bool,
nProcessors: null == nProcessors
? _value.nProcessors
: nProcessors // ignore: cast_nullable_to_non_nullable
as int,
splitOnWord: null == splitOnWord
? _value.splitOnWord
: splitOnWord // ignore: cast_nullable_to_non_nullable
as bool,
noFallback: null == noFallback
? _value.noFallback
: noFallback // ignore: cast_nullable_to_non_nullable
as bool,
diarize: null == diarize
? _value.diarize
: diarize // ignore: cast_nullable_to_non_nullable
as bool,
speedUp: null == speedUp
? _value.speedUp
: speedUp // ignore: cast_nullable_to_non_nullable
as bool,
));
}
}
/// @nodoc
@JsonSerializable()
class _$TranscribeRequestDtoImpl extends _TranscribeRequestDto {
const _$TranscribeRequestDtoImpl(
{required this.audio,
required this.model,
@JsonKey(name: 'is_translate') required this.isTranslate,
required this.threads,
@JsonKey(name: 'is_verbose') required this.isVerbose,
required this.language,
@JsonKey(name: 'is_special_tokens') required this.isSpecialTokens,
@JsonKey(name: 'is_no_timestamps') required this.isNoTimestamps,
@JsonKey(name: 'n_processors') required this.nProcessors,
@JsonKey(name: 'split_on_word') required this.splitOnWord,
@JsonKey(name: 'no_fallback') required this.noFallback,
required this.diarize,
@JsonKey(name: 'speed_up') required this.speedUp})
: super._();
factory _$TranscribeRequestDtoImpl.fromJson(Map<String, dynamic> json) =>
_$$TranscribeRequestDtoImplFromJson(json);
@override
final String audio;
@override
final String model;
@override
@JsonKey(name: 'is_translate')
final bool isTranslate;
@override
final int threads;
@override
@JsonKey(name: 'is_verbose')
final bool isVerbose;
@override
final String language;
@override
@JsonKey(name: 'is_special_tokens')
final bool isSpecialTokens;
@override
@JsonKey(name: 'is_no_timestamps')
final bool isNoTimestamps;
@override
@JsonKey(name: 'n_processors')
final int nProcessors;
@override
@JsonKey(name: 'split_on_word')
final bool splitOnWord;
@override
@JsonKey(name: 'no_fallback')
final bool noFallback;
@override
final bool diarize;
@override
@JsonKey(name: 'speed_up')
final bool speedUp;
@override
String toString() {
return 'TranscribeRequestDto(audio: $audio, model: $model, isTranslate: $isTranslate, threads: $threads, isVerbose: $isVerbose, language: $language, isSpecialTokens: $isSpecialTokens, isNoTimestamps: $isNoTimestamps, nProcessors: $nProcessors, splitOnWord: $splitOnWord, noFallback: $noFallback, diarize: $diarize, speedUp: $speedUp)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$TranscribeRequestDtoImpl &&
(identical(other.audio, audio) || other.audio == audio) &&
(identical(other.model, model) || other.model == model) &&
(identical(other.isTranslate, isTranslate) ||
other.isTranslate == isTranslate) &&
(identical(other.threads, threads) || other.threads == threads) &&
(identical(other.isVerbose, isVerbose) ||
other.isVerbose == isVerbose) &&
(identical(other.language, language) ||
other.language == language) &&
(identical(other.isSpecialTokens, isSpecialTokens) ||
other.isSpecialTokens == isSpecialTokens) &&
(identical(other.isNoTimestamps, isNoTimestamps) ||
other.isNoTimestamps == isNoTimestamps) &&
(identical(other.nProcessors, nProcessors) ||
other.nProcessors == nProcessors) &&
(identical(other.splitOnWord, splitOnWord) ||
other.splitOnWord == splitOnWord) &&
(identical(other.noFallback, noFallback) ||
other.noFallback == noFallback) &&
(identical(other.diarize, diarize) || other.diarize == diarize) &&
(identical(other.speedUp, speedUp) || other.speedUp == speedUp));
}
@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(
runtimeType,
audio,
model,
isTranslate,
threads,
isVerbose,
language,
isSpecialTokens,
isNoTimestamps,
nProcessors,
splitOnWord,
noFallback,
diarize,
speedUp);
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$TranscribeRequestDtoImplCopyWith<_$TranscribeRequestDtoImpl>
get copyWith =>
__$$TranscribeRequestDtoImplCopyWithImpl<_$TranscribeRequestDtoImpl>(
this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$TranscribeRequestDtoImplToJson(
this,
);
}
}
abstract class _TranscribeRequestDto extends TranscribeRequestDto {
const factory _TranscribeRequestDto(
{required final String audio,
required final String model,
@JsonKey(name: 'is_translate') required final bool isTranslate,
required final int threads,
@JsonKey(name: 'is_verbose') required final bool isVerbose,
required final String language,
@JsonKey(name: 'is_special_tokens') required final bool isSpecialTokens,
@JsonKey(name: 'is_no_timestamps') required final bool isNoTimestamps,
@JsonKey(name: 'n_processors') required final int nProcessors,
@JsonKey(name: 'split_on_word') required final bool splitOnWord,
@JsonKey(name: 'no_fallback') required final bool noFallback,
required final bool diarize,
@JsonKey(name: 'speed_up')
required final bool speedUp}) = _$TranscribeRequestDtoImpl;
const _TranscribeRequestDto._() : super._();
factory _TranscribeRequestDto.fromJson(Map<String, dynamic> json) =
_$TranscribeRequestDtoImpl.fromJson;
@override
String get audio;
@override
String get model;
@override
@JsonKey(name: 'is_translate')
bool get isTranslate;
@override
int get threads;
@override
@JsonKey(name: 'is_verbose')
bool get isVerbose;
@override
String get language;
@override
@JsonKey(name: 'is_special_tokens')
bool get isSpecialTokens;
@override
@JsonKey(name: 'is_no_timestamps')
bool get isNoTimestamps;
@override
@JsonKey(name: 'n_processors')
int get nProcessors;
@override
@JsonKey(name: 'split_on_word')
bool get splitOnWord;
@override
@JsonKey(name: 'no_fallback')
bool get noFallback;
@override
bool get diarize;
@override
@JsonKey(name: 'speed_up')
bool get speedUp;
@override
@JsonKey(ignore: true)
_$$TranscribeRequestDtoImplCopyWith<_$TranscribeRequestDtoImpl>
get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$VersionRequest {}
/// @nodoc
abstract class $VersionRequestCopyWith<$Res> {
factory $VersionRequestCopyWith(
VersionRequest value, $Res Function(VersionRequest) then) =
_$VersionRequestCopyWithImpl<$Res, VersionRequest>;
}
/// @nodoc
class _$VersionRequestCopyWithImpl<$Res, $Val extends VersionRequest>
implements $VersionRequestCopyWith<$Res> {
_$VersionRequestCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
}
/// @nodoc
abstract class _$$VersionRequestImplCopyWith<$Res> {
factory _$$VersionRequestImplCopyWith(_$VersionRequestImpl value,
$Res Function(_$VersionRequestImpl) then) =
__$$VersionRequestImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$VersionRequestImplCopyWithImpl<$Res>
extends _$VersionRequestCopyWithImpl<$Res, _$VersionRequestImpl>
implements _$$VersionRequestImplCopyWith<$Res> {
__$$VersionRequestImplCopyWithImpl(
_$VersionRequestImpl _value, $Res Function(_$VersionRequestImpl) _then)
: super(_value, _then);
}
/// @nodoc
class _$VersionRequestImpl extends _VersionRequest {
const _$VersionRequestImpl() : super._();
@override
String toString() {
return 'VersionRequest()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$VersionRequestImpl);
}
@override
int get hashCode => runtimeType.hashCode;
}
abstract class _VersionRequest extends VersionRequest {
const factory _VersionRequest() = _$VersionRequestImpl;
const _VersionRequest._() : super._();
}

View File

@@ -0,0 +1,77 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'request_bean.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$TranscribeRequestImpl _$$TranscribeRequestImplFromJson(
Map<String, dynamic> json) =>
_$TranscribeRequestImpl(
audio: json['audio'] as String,
isTranslate: json['isTranslate'] as bool? ?? false,
threads: (json['threads'] as num?)?.toInt() ?? 8,
isVerbose: json['isVerbose'] as bool? ?? false,
language: json['language'] as String? ?? 'auto',
isSpecialTokens: json['isSpecialTokens'] as bool? ?? false,
isNoTimestamps: json['isNoTimestamps'] as bool? ?? false,
nProcessors: (json['nProcessors'] as num?)?.toInt() ?? 1,
splitOnWord: json['splitOnWord'] as bool? ?? false,
noFallback: json['noFallback'] as bool? ?? false,
diarize: json['diarize'] as bool? ?? false,
speedUp: json['speedUp'] as bool? ?? false,
);
Map<String, dynamic> _$$TranscribeRequestImplToJson(
_$TranscribeRequestImpl instance) =>
<String, dynamic>{
'audio': instance.audio,
'isTranslate': instance.isTranslate,
'threads': instance.threads,
'isVerbose': instance.isVerbose,
'language': instance.language,
'isSpecialTokens': instance.isSpecialTokens,
'isNoTimestamps': instance.isNoTimestamps,
'nProcessors': instance.nProcessors,
'splitOnWord': instance.splitOnWord,
'noFallback': instance.noFallback,
'diarize': instance.diarize,
'speedUp': instance.speedUp,
};
_$TranscribeRequestDtoImpl _$$TranscribeRequestDtoImplFromJson(
Map<String, dynamic> json) =>
_$TranscribeRequestDtoImpl(
audio: json['audio'] as String,
model: json['model'] as String,
isTranslate: json['is_translate'] as bool,
threads: (json['threads'] as num).toInt(),
isVerbose: json['is_verbose'] as bool,
language: json['language'] as String,
isSpecialTokens: json['is_special_tokens'] as bool,
isNoTimestamps: json['is_no_timestamps'] as bool,
nProcessors: (json['n_processors'] as num).toInt(),
splitOnWord: json['split_on_word'] as bool,
noFallback: json['no_fallback'] as bool,
diarize: json['diarize'] as bool,
speedUp: json['speed_up'] as bool,
);
Map<String, dynamic> _$$TranscribeRequestDtoImplToJson(
_$TranscribeRequestDtoImpl instance) =>
<String, dynamic>{
'audio': instance.audio,
'model': instance.model,
'is_translate': instance.isTranslate,
'threads': instance.threads,
'is_verbose': instance.isVerbose,
'language': instance.language,
'is_special_tokens': instance.isSpecialTokens,
'is_no_timestamps': instance.isNoTimestamps,
'n_processors': instance.nProcessors,
'split_on_word': instance.splitOnWord,
'no_fallback': instance.noFallback,
'diarize': instance.diarize,
'speed_up': instance.speedUp,
};

View File

@@ -0,0 +1,63 @@
/*
* Copyright (c) 田梓萱[小草林] 2021-2024.
* All Rights Reserved.
* All codes are protected by China's regulations on the protection of computer software, and infringement must be investigated.
* 版权所有 (c) 田梓萱[小草林] 2021-2024.
* 所有代码均受中国《计算机软件保护条例》保护,侵权必究.
*/
import "package:freezed_annotation/freezed_annotation.dart";
part "response_bean.freezed.dart";
part "response_bean.g.dart";
@unfreezed
class WhisperTranscribeResponse with _$WhisperTranscribeResponse {
factory WhisperTranscribeResponse({
@JsonKey(name: "@type") required String type,
required String text,
@JsonKey(name: "segments")
required List<WhisperTranscribeSegment>? segments,
}) = _WhisperTranscribeResponse;
factory WhisperTranscribeResponse.fromJson(Map<String, dynamic> json) =>
_$WhisperTranscribeResponseFromJson(json);
}
@unfreezed
class WhisperTranscribeSegment with _$WhisperTranscribeSegment {
///
factory WhisperTranscribeSegment({
@JsonKey(
name: "from_ts",
fromJson: WhisperTranscribeSegment._durationFromInt,
)
required Duration fromTs,
@JsonKey(
name: "to_ts",
fromJson: WhisperTranscribeSegment._durationFromInt,
)
required Duration toTs,
required String text,
}) = _WhisperTranscribeSegment;
/// Parse [json] to WhisperTranscribeSegment
factory WhisperTranscribeSegment.fromJson(Map<String, dynamic> json) =>
_$WhisperTranscribeSegmentFromJson(json);
static Duration _durationFromInt(int timestamp) {
return Duration(
milliseconds: timestamp * 10,
);
}
}
@unfreezed
class WhisperVersionResponse with _$WhisperVersionResponse {
factory WhisperVersionResponse({
@JsonKey(name: "@type") required String type,
required String message,
}) = _WhisperVersionResponse;
factory WhisperVersionResponse.fromJson(Map<String, dynamic> json) =>
_$WhisperVersionResponseFromJson(json);
}

View File

@@ -0,0 +1,568 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'response_bean.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
WhisperTranscribeResponse _$WhisperTranscribeResponseFromJson(
Map<String, dynamic> json) {
return _WhisperTranscribeResponse.fromJson(json);
}
/// @nodoc
mixin _$WhisperTranscribeResponse {
@JsonKey(name: '@type')
String get type => throw _privateConstructorUsedError;
@JsonKey(name: '@type')
set type(String value) => throw _privateConstructorUsedError;
String get text => throw _privateConstructorUsedError;
set text(String value) => throw _privateConstructorUsedError;
@JsonKey(name: 'segments')
List<WhisperTranscribeSegment>? get segments =>
throw _privateConstructorUsedError;
@JsonKey(name: 'segments')
set segments(List<WhisperTranscribeSegment>? value) =>
throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$WhisperTranscribeResponseCopyWith<WhisperTranscribeResponse> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $WhisperTranscribeResponseCopyWith<$Res> {
factory $WhisperTranscribeResponseCopyWith(WhisperTranscribeResponse value,
$Res Function(WhisperTranscribeResponse) then) =
_$WhisperTranscribeResponseCopyWithImpl<$Res, WhisperTranscribeResponse>;
@useResult
$Res call(
{@JsonKey(name: '@type') String type,
String text,
@JsonKey(name: 'segments') List<WhisperTranscribeSegment>? segments});
}
/// @nodoc
class _$WhisperTranscribeResponseCopyWithImpl<$Res,
$Val extends WhisperTranscribeResponse>
implements $WhisperTranscribeResponseCopyWith<$Res> {
_$WhisperTranscribeResponseCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
@pragma('vm:prefer-inline')
@override
$Res call({
Object? type = null,
Object? text = null,
Object? segments = freezed,
}) {
return _then(_value.copyWith(
type: null == type
? _value.type
: type // ignore: cast_nullable_to_non_nullable
as String,
text: null == text
? _value.text
: text // ignore: cast_nullable_to_non_nullable
as String,
segments: freezed == segments
? _value.segments
: segments // ignore: cast_nullable_to_non_nullable
as List<WhisperTranscribeSegment>?,
) as $Val);
}
}
/// @nodoc
abstract class _$$WhisperTranscribeResponseImplCopyWith<$Res>
implements $WhisperTranscribeResponseCopyWith<$Res> {
factory _$$WhisperTranscribeResponseImplCopyWith(
_$WhisperTranscribeResponseImpl value,
$Res Function(_$WhisperTranscribeResponseImpl) then) =
__$$WhisperTranscribeResponseImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{@JsonKey(name: '@type') String type,
String text,
@JsonKey(name: 'segments') List<WhisperTranscribeSegment>? segments});
}
/// @nodoc
class __$$WhisperTranscribeResponseImplCopyWithImpl<$Res>
extends _$WhisperTranscribeResponseCopyWithImpl<$Res,
_$WhisperTranscribeResponseImpl>
implements _$$WhisperTranscribeResponseImplCopyWith<$Res> {
__$$WhisperTranscribeResponseImplCopyWithImpl(
_$WhisperTranscribeResponseImpl _value,
$Res Function(_$WhisperTranscribeResponseImpl) _then)
: super(_value, _then);
@pragma('vm:prefer-inline')
@override
$Res call({
Object? type = null,
Object? text = null,
Object? segments = freezed,
}) {
return _then(_$WhisperTranscribeResponseImpl(
type: null == type
? _value.type
: type // ignore: cast_nullable_to_non_nullable
as String,
text: null == text
? _value.text
: text // ignore: cast_nullable_to_non_nullable
as String,
segments: freezed == segments
? _value.segments
: segments // ignore: cast_nullable_to_non_nullable
as List<WhisperTranscribeSegment>?,
));
}
}
/// @nodoc
@JsonSerializable()
class _$WhisperTranscribeResponseImpl implements _WhisperTranscribeResponse {
_$WhisperTranscribeResponseImpl(
{@JsonKey(name: '@type') required this.type,
required this.text,
@JsonKey(name: 'segments') required this.segments});
factory _$WhisperTranscribeResponseImpl.fromJson(Map<String, dynamic> json) =>
_$$WhisperTranscribeResponseImplFromJson(json);
@override
@JsonKey(name: '@type')
String type;
@override
String text;
@override
@JsonKey(name: 'segments')
List<WhisperTranscribeSegment>? segments;
@override
String toString() {
return 'WhisperTranscribeResponse(type: $type, text: $text, segments: $segments)';
}
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$WhisperTranscribeResponseImplCopyWith<_$WhisperTranscribeResponseImpl>
get copyWith => __$$WhisperTranscribeResponseImplCopyWithImpl<
_$WhisperTranscribeResponseImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$WhisperTranscribeResponseImplToJson(
this,
);
}
}
abstract class _WhisperTranscribeResponse implements WhisperTranscribeResponse {
factory _WhisperTranscribeResponse(
{@JsonKey(name: '@type') required String type,
required String text,
@JsonKey(name: 'segments')
required List<WhisperTranscribeSegment>? segments}) =
_$WhisperTranscribeResponseImpl;
factory _WhisperTranscribeResponse.fromJson(Map<String, dynamic> json) =
_$WhisperTranscribeResponseImpl.fromJson;
@override
@JsonKey(name: '@type')
String get type;
@JsonKey(name: '@type')
set type(String value);
@override
String get text;
set text(String value);
@override
@JsonKey(name: 'segments')
List<WhisperTranscribeSegment>? get segments;
@JsonKey(name: 'segments')
set segments(List<WhisperTranscribeSegment>? value);
@override
@JsonKey(ignore: true)
_$$WhisperTranscribeResponseImplCopyWith<_$WhisperTranscribeResponseImpl>
get copyWith => throw _privateConstructorUsedError;
}
WhisperTranscribeSegment _$WhisperTranscribeSegmentFromJson(
Map<String, dynamic> json) {
return _WhisperTranscribeSegment.fromJson(json);
}
/// @nodoc
mixin _$WhisperTranscribeSegment {
@JsonKey(name: 'from_ts', fromJson: WhisperTranscribeSegment._durationFromInt)
Duration get fromTs => throw _privateConstructorUsedError;
@JsonKey(name: 'from_ts', fromJson: WhisperTranscribeSegment._durationFromInt)
set fromTs(Duration value) => throw _privateConstructorUsedError;
@JsonKey(name: 'to_ts', fromJson: WhisperTranscribeSegment._durationFromInt)
Duration get toTs => throw _privateConstructorUsedError;
@JsonKey(name: 'to_ts', fromJson: WhisperTranscribeSegment._durationFromInt)
set toTs(Duration value) => throw _privateConstructorUsedError;
String get text => throw _privateConstructorUsedError;
set text(String value) => throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$WhisperTranscribeSegmentCopyWith<WhisperTranscribeSegment> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $WhisperTranscribeSegmentCopyWith<$Res> {
factory $WhisperTranscribeSegmentCopyWith(WhisperTranscribeSegment value,
$Res Function(WhisperTranscribeSegment) then) =
_$WhisperTranscribeSegmentCopyWithImpl<$Res, WhisperTranscribeSegment>;
@useResult
$Res call(
{@JsonKey(
name: 'from_ts', fromJson: WhisperTranscribeSegment._durationFromInt)
Duration fromTs,
@JsonKey(
name: 'to_ts', fromJson: WhisperTranscribeSegment._durationFromInt)
Duration toTs,
String text});
}
/// @nodoc
class _$WhisperTranscribeSegmentCopyWithImpl<$Res,
$Val extends WhisperTranscribeSegment>
implements $WhisperTranscribeSegmentCopyWith<$Res> {
_$WhisperTranscribeSegmentCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
@pragma('vm:prefer-inline')
@override
$Res call({
Object? fromTs = null,
Object? toTs = null,
Object? text = null,
}) {
return _then(_value.copyWith(
fromTs: null == fromTs
? _value.fromTs
: fromTs // ignore: cast_nullable_to_non_nullable
as Duration,
toTs: null == toTs
? _value.toTs
: toTs // ignore: cast_nullable_to_non_nullable
as Duration,
text: null == text
? _value.text
: text // ignore: cast_nullable_to_non_nullable
as String,
) as $Val);
}
}
/// @nodoc
abstract class _$$WhisperTranscribeSegmentImplCopyWith<$Res>
implements $WhisperTranscribeSegmentCopyWith<$Res> {
factory _$$WhisperTranscribeSegmentImplCopyWith(
_$WhisperTranscribeSegmentImpl value,
$Res Function(_$WhisperTranscribeSegmentImpl) then) =
__$$WhisperTranscribeSegmentImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{@JsonKey(
name: 'from_ts', fromJson: WhisperTranscribeSegment._durationFromInt)
Duration fromTs,
@JsonKey(
name: 'to_ts', fromJson: WhisperTranscribeSegment._durationFromInt)
Duration toTs,
String text});
}
/// @nodoc
class __$$WhisperTranscribeSegmentImplCopyWithImpl<$Res>
extends _$WhisperTranscribeSegmentCopyWithImpl<$Res,
_$WhisperTranscribeSegmentImpl>
implements _$$WhisperTranscribeSegmentImplCopyWith<$Res> {
__$$WhisperTranscribeSegmentImplCopyWithImpl(
_$WhisperTranscribeSegmentImpl _value,
$Res Function(_$WhisperTranscribeSegmentImpl) _then)
: super(_value, _then);
@pragma('vm:prefer-inline')
@override
$Res call({
Object? fromTs = null,
Object? toTs = null,
Object? text = null,
}) {
return _then(_$WhisperTranscribeSegmentImpl(
fromTs: null == fromTs
? _value.fromTs
: fromTs // ignore: cast_nullable_to_non_nullable
as Duration,
toTs: null == toTs
? _value.toTs
: toTs // ignore: cast_nullable_to_non_nullable
as Duration,
text: null == text
? _value.text
: text // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
@JsonSerializable()
class _$WhisperTranscribeSegmentImpl implements _WhisperTranscribeSegment {
_$WhisperTranscribeSegmentImpl(
{@JsonKey(
name: 'from_ts', fromJson: WhisperTranscribeSegment._durationFromInt)
required this.fromTs,
@JsonKey(
name: 'to_ts', fromJson: WhisperTranscribeSegment._durationFromInt)
required this.toTs,
required this.text});
factory _$WhisperTranscribeSegmentImpl.fromJson(Map<String, dynamic> json) =>
_$$WhisperTranscribeSegmentImplFromJson(json);
@override
@JsonKey(name: 'from_ts', fromJson: WhisperTranscribeSegment._durationFromInt)
Duration fromTs;
@override
@JsonKey(name: 'to_ts', fromJson: WhisperTranscribeSegment._durationFromInt)
Duration toTs;
@override
String text;
@override
String toString() {
return 'WhisperTranscribeSegment(fromTs: $fromTs, toTs: $toTs, text: $text)';
}
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$WhisperTranscribeSegmentImplCopyWith<_$WhisperTranscribeSegmentImpl>
get copyWith => __$$WhisperTranscribeSegmentImplCopyWithImpl<
_$WhisperTranscribeSegmentImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$WhisperTranscribeSegmentImplToJson(
this,
);
}
}
abstract class _WhisperTranscribeSegment implements WhisperTranscribeSegment {
factory _WhisperTranscribeSegment(
{@JsonKey(
name: 'from_ts', fromJson: WhisperTranscribeSegment._durationFromInt)
required Duration fromTs,
@JsonKey(
name: 'to_ts', fromJson: WhisperTranscribeSegment._durationFromInt)
required Duration toTs,
required String text}) = _$WhisperTranscribeSegmentImpl;
factory _WhisperTranscribeSegment.fromJson(Map<String, dynamic> json) =
_$WhisperTranscribeSegmentImpl.fromJson;
@override
@JsonKey(name: 'from_ts', fromJson: WhisperTranscribeSegment._durationFromInt)
Duration get fromTs;
@JsonKey(name: 'from_ts', fromJson: WhisperTranscribeSegment._durationFromInt)
set fromTs(Duration value);
@override
@JsonKey(name: 'to_ts', fromJson: WhisperTranscribeSegment._durationFromInt)
Duration get toTs;
@JsonKey(name: 'to_ts', fromJson: WhisperTranscribeSegment._durationFromInt)
set toTs(Duration value);
@override
String get text;
set text(String value);
@override
@JsonKey(ignore: true)
_$$WhisperTranscribeSegmentImplCopyWith<_$WhisperTranscribeSegmentImpl>
get copyWith => throw _privateConstructorUsedError;
}
WhisperVersionResponse _$WhisperVersionResponseFromJson(
Map<String, dynamic> json) {
return _WhisperVersionResponse.fromJson(json);
}
/// @nodoc
mixin _$WhisperVersionResponse {
@JsonKey(name: '@type')
String get type => throw _privateConstructorUsedError;
@JsonKey(name: '@type')
set type(String value) => throw _privateConstructorUsedError;
String get message => throw _privateConstructorUsedError;
set message(String value) => throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$WhisperVersionResponseCopyWith<WhisperVersionResponse> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $WhisperVersionResponseCopyWith<$Res> {
factory $WhisperVersionResponseCopyWith(WhisperVersionResponse value,
$Res Function(WhisperVersionResponse) then) =
_$WhisperVersionResponseCopyWithImpl<$Res, WhisperVersionResponse>;
@useResult
$Res call({@JsonKey(name: '@type') String type, String message});
}
/// @nodoc
class _$WhisperVersionResponseCopyWithImpl<$Res,
$Val extends WhisperVersionResponse>
implements $WhisperVersionResponseCopyWith<$Res> {
_$WhisperVersionResponseCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
@pragma('vm:prefer-inline')
@override
$Res call({
Object? type = null,
Object? message = null,
}) {
return _then(_value.copyWith(
type: null == type
? _value.type
: type // ignore: cast_nullable_to_non_nullable
as String,
message: null == message
? _value.message
: message // ignore: cast_nullable_to_non_nullable
as String,
) as $Val);
}
}
/// @nodoc
abstract class _$$WhisperVersionResponseImplCopyWith<$Res>
implements $WhisperVersionResponseCopyWith<$Res> {
factory _$$WhisperVersionResponseImplCopyWith(
_$WhisperVersionResponseImpl value,
$Res Function(_$WhisperVersionResponseImpl) then) =
__$$WhisperVersionResponseImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({@JsonKey(name: '@type') String type, String message});
}
/// @nodoc
class __$$WhisperVersionResponseImplCopyWithImpl<$Res>
extends _$WhisperVersionResponseCopyWithImpl<$Res,
_$WhisperVersionResponseImpl>
implements _$$WhisperVersionResponseImplCopyWith<$Res> {
__$$WhisperVersionResponseImplCopyWithImpl(
_$WhisperVersionResponseImpl _value,
$Res Function(_$WhisperVersionResponseImpl) _then)
: super(_value, _then);
@pragma('vm:prefer-inline')
@override
$Res call({
Object? type = null,
Object? message = null,
}) {
return _then(_$WhisperVersionResponseImpl(
type: null == type
? _value.type
: type // ignore: cast_nullable_to_non_nullable
as String,
message: null == message
? _value.message
: message // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
@JsonSerializable()
class _$WhisperVersionResponseImpl implements _WhisperVersionResponse {
_$WhisperVersionResponseImpl(
{@JsonKey(name: '@type') required this.type, required this.message});
factory _$WhisperVersionResponseImpl.fromJson(Map<String, dynamic> json) =>
_$$WhisperVersionResponseImplFromJson(json);
@override
@JsonKey(name: '@type')
String type;
@override
String message;
@override
String toString() {
return 'WhisperVersionResponse(type: $type, message: $message)';
}
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$WhisperVersionResponseImplCopyWith<_$WhisperVersionResponseImpl>
get copyWith => __$$WhisperVersionResponseImplCopyWithImpl<
_$WhisperVersionResponseImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$WhisperVersionResponseImplToJson(
this,
);
}
}
abstract class _WhisperVersionResponse implements WhisperVersionResponse {
factory _WhisperVersionResponse(
{@JsonKey(name: '@type') required String type,
required String message}) = _$WhisperVersionResponseImpl;
factory _WhisperVersionResponse.fromJson(Map<String, dynamic> json) =
_$WhisperVersionResponseImpl.fromJson;
@override
@JsonKey(name: '@type')
String get type;
@JsonKey(name: '@type')
set type(String value);
@override
String get message;
set message(String value);
@override
@JsonKey(ignore: true)
_$$WhisperVersionResponseImplCopyWith<_$WhisperVersionResponseImpl>
get copyWith => throw _privateConstructorUsedError;
}

View File

@@ -0,0 +1,58 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'response_bean.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$WhisperTranscribeResponseImpl _$$WhisperTranscribeResponseImplFromJson(
Map<String, dynamic> json) =>
_$WhisperTranscribeResponseImpl(
type: json['@type'] as String,
text: json['text'] as String,
segments: (json['segments'] as List<dynamic>?)
?.map((e) =>
WhisperTranscribeSegment.fromJson(e as Map<String, dynamic>))
.toList(),
);
Map<String, dynamic> _$$WhisperTranscribeResponseImplToJson(
_$WhisperTranscribeResponseImpl instance) =>
<String, dynamic>{
'@type': instance.type,
'text': instance.text,
'segments': instance.segments,
};
_$WhisperTranscribeSegmentImpl _$$WhisperTranscribeSegmentImplFromJson(
Map<String, dynamic> json) =>
_$WhisperTranscribeSegmentImpl(
fromTs: WhisperTranscribeSegment._durationFromInt(
(json['from_ts'] as num).toInt()),
toTs: WhisperTranscribeSegment._durationFromInt(
(json['to_ts'] as num).toInt()),
text: json['text'] as String,
);
Map<String, dynamic> _$$WhisperTranscribeSegmentImplToJson(
_$WhisperTranscribeSegmentImpl instance) =>
<String, dynamic>{
'from_ts': instance.fromTs.inMicroseconds,
'to_ts': instance.toTs.inMicroseconds,
'text': instance.text,
};
_$WhisperVersionResponseImpl _$$WhisperVersionResponseImplFromJson(
Map<String, dynamic> json) =>
_$WhisperVersionResponseImpl(
type: json['@type'] as String,
message: json['message'] as String,
);
Map<String, dynamic> _$$WhisperVersionResponseImplToJson(
_$WhisperVersionResponseImpl instance) =>
<String, dynamic>{
'@type': instance.type,
'message': instance.message,
};

View File

@@ -0,0 +1,8 @@
/// Common whisper request
abstract class WhisperRequestDto {
/// Convert current request to String encoded whisper json
String toRequestString();
/// Type of request or response
String get specialType;
}

87
lib/download_model.dart Normal file
View File

@@ -0,0 +1,87 @@
/*
* Copyright (c) 田梓萱[小草林] 2021-2024.
* All Rights Reserved.
* All codes are protected by China's regulations on the protection of computer software, and infringement must be investigated.
* 版权所有 (c) 田梓萱[小草林] 2021-2024.
* 所有代码均受中国《计算机软件保护条例》保护,侵权必究.
*/
import "dart:io";
import "package:flutter/foundation.dart";
/// Available whisper models
enum WhisperModel {
// no model
none(""),
/// tiny model for all languages
tiny("tiny"),
/// base model for all languages
base("base"),
/// small model for all languages
small("small"),
/// medium model for all languages
medium("medium"),
/// large model for all languages
largeV1("large-v1"),
largeV2("large-v2");
const WhisperModel(this.modelName);
/// Public name of model
final String modelName;
/// Get local path of model file
String getPath(String dir) {
return "$dir/ggml-$modelName.bin";
}
}
/// Download [model] to [destinationPath]
Future<String> downloadModel(
{required WhisperModel model,
required String destinationPath,
String? downloadHost}) async {
if (kDebugMode) {
debugPrint("Download model ${model.modelName}");
}
final httpClient = HttpClient();
Uri modelUri;
if (downloadHost == null || downloadHost.isEmpty) {
/// Huggingface url to download model
modelUri = Uri.parse(
"https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-${model.modelName}.bin",
);
} else {
modelUri = Uri.parse(
"$downloadHost/ggml-${model.modelName}.bin",
);
}
final request = await httpClient.getUrl(
modelUri,
);
final response = await request.close();
final file = File("$destinationPath/ggml-${model.modelName}.bin");
final raf = file.openSync(mode: FileMode.write);
await for (var chunk in response) {
raf.writeFromSync(chunk);
}
await raf.close();
if (kDebugMode) {
debugPrint("Download Down . Path = ${file.path}");
}
return file.path;
}

View File

@@ -0,0 +1,39 @@
// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
// ignore_for_file: type=lint
import 'dart:ffi' as ffi;
/// Bindings for `src/main.h`.
///
/// Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`.
///
class WhisperFlutterBindings {
/// Holds the symbol lookup function.
final ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
_lookup;
/// The symbols are looked up in [dynamicLibrary].
WhisperFlutterBindings(ffi.DynamicLibrary dynamicLibrary)
: _lookup = dynamicLibrary.lookup;
/// The symbols are looked up with [lookup].
WhisperFlutterBindings.fromLookup(
ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
lookup)
: _lookup = lookup;
ffi.Pointer<ffi.Char> request(
ffi.Pointer<ffi.Char> body,
) {
return _request(
body,
);
}
late final _requestPtr = _lookup<
ffi.NativeFunction<
ffi.Pointer<ffi.Char> Function(ffi.Pointer<ffi.Char>)>>('request');
late final _request = _requestPtr
.asFunction<ffi.Pointer<ffi.Char> Function(ffi.Pointer<ffi.Char>)>();
}

View File

@@ -0,0 +1,135 @@
/*
* Copyright (c) 田梓萱[小草林] 2021-2024.
* All Rights Reserved.
* All codes are protected by China's regulations on the protection of computer software, and infringement must be investigated.
* 版权所有 (c) 田梓萱[小草林] 2021-2024.
* 所有代码均受中国《计算机软件保护条例》保护,侵权必究.
*/
import "dart:convert";
import "dart:ffi";
import "dart:io";
import "dart:isolate";
import "package:ffi/ffi.dart";
import "package:flutter/foundation.dart";
import "package:path_provider/path_provider.dart";
import "package:whisper_flutter_new/bean/_models.dart";
import "package:whisper_flutter_new/bean/whisper_dto.dart";
import "package:whisper_flutter_new/download_model.dart";
import "package:whisper_flutter_new/whisper_bindings_generated.dart";
export "package:whisper_flutter_new/bean/_models.dart";
export "package:whisper_flutter_new/download_model.dart" show WhisperModel;
/// Entry point of whisper_flutter_plus
class Whisper {
/// [model] is required
/// [modelDir] is path where downloaded model will be stored.
/// Default to library directory
const Whisper({required this.model, this.modelDir, this.downloadHost});
/// model used for transcription
final WhisperModel model;
/// override of model storage path
final String? modelDir;
// override of model download host
final String? downloadHost;
DynamicLibrary _openLib() {
if (Platform.isAndroid) {
return DynamicLibrary.open("libwhisper.so");
} else {
return DynamicLibrary.process();
}
}
Future<String> _getModelDir() async {
if (modelDir != null) {
return modelDir!;
}
final Directory libraryDirectory = Platform.isAndroid
? await getApplicationSupportDirectory()
: await getLibraryDirectory();
return libraryDirectory.path;
}
Future<void> _initModel() async {
final String modelDir = await _getModelDir();
final File modelFile = File(model.getPath(modelDir));
final bool isModelExist = modelFile.existsSync();
if (isModelExist) {
if (kDebugMode) {
debugPrint("Use existing model ${model.modelName}");
}
return;
} else {
await downloadModel(
model: model, destinationPath: modelDir, downloadHost: downloadHost);
}
}
Future<Map<String, dynamic>> _request({
required WhisperRequestDto whisperRequest,
}) async {
if (model != WhisperModel.none) {
await _initModel();
}
return Isolate.run(
() async {
final Pointer<Utf8> data =
whisperRequest.toRequestString().toNativeUtf8();
final Pointer<Char> res =
WhisperFlutterBindings(_openLib()).request(data.cast<Char>());
final Map<String, dynamic> result = json.decode(
res.cast<Utf8>().toDartString(),
) as Map<String, dynamic>;
try {
malloc.free(data);
malloc.free(res);
} catch (_) {}
if (kDebugMode) {
debugPrint("Result = $result");
}
return result;
},
);
}
/// Transcribe audio file to text
Future<WhisperTranscribeResponse> transcribe({
required TranscribeRequest transcribeRequest,
}) async {
final String modelDir = await _getModelDir();
final Map<String, dynamic> result = await _request(
whisperRequest: TranscribeRequestDto.fromTranscribeRequest(
transcribeRequest,
model.getPath(modelDir),
),
);
if (kDebugMode) {
debugPrint("Transcribe request $result");
}
if (result["text"] == null) {
if (kDebugMode) {
debugPrint('Transcribe Exception ${result['message']}');
}
throw Exception(result["message"]);
}
return WhisperTranscribeResponse.fromJson(result);
}
/// Get whisper version
Future<String?> getVersion() async {
final Map<String, dynamic> result = await _request(
whisperRequest: const VersionRequest(),
);
final WhisperVersionResponse response = WhisperVersionResponse.fromJson(
result,
);
return response.message;
}
}