36 lines
1.3 KiB
Dart
36 lines
1.3 KiB
Dart
import 'dart:io';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:kouyu_english/core/ai_service.dart';
|
|
import 'package:kouyu_english/core/models.dart';
|
|
|
|
void main() {
|
|
test('transcribeAudio with valid test audio file returns transcription', () async {
|
|
final ai = AiService.instance;
|
|
ai.setFallbackApiKey('sk-242EMNuXYjxSEktp91E8QqS8ejGs9XImrDddIA5JHXdeCKLSUcB91vrSmhyv45pf');
|
|
|
|
// Create a temporary wav file if not exists
|
|
final tempFile = File('/tmp/test_unit.wav');
|
|
if (!await tempFile.exists()) {
|
|
// 44-byte standard wav header with 1 second silence
|
|
final wavHeader = <int>[
|
|
0x52, 0x49, 0x46, 0x46, 0x24, 0x7d, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45,
|
|
0x66, 0x6d, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
|
|
0x80, 0x3e, 0x00, 0x00, 0x00, 0x7d, 0x00, 0x00, 0x02, 0x00, 0x10, 0x00,
|
|
0x64, 0x61, 0x74, 0x61, 0x00, 0x7d, 0x00, 0x00,
|
|
];
|
|
final wavData = List<int>.filled(32000, 0);
|
|
await tempFile.writeAsBytes(wavHeader + wavData);
|
|
}
|
|
|
|
final result = await ai.transcribeAudio(
|
|
filePath: tempFile.path,
|
|
provider: AiProviderType.compatible,
|
|
endpoint: 'https://codex.slcydia.fun/v1/responses',
|
|
model: 'gemini-3.7-flash-high',
|
|
);
|
|
|
|
print('Transcribe result: $result');
|
|
expect(result, isNotNull);
|
|
});
|
|
}
|