feat: add AI voice transcription fallback for domestic Android ROMs
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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('***REMOVED***');
|
||||
|
||||
// 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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user