新增 logger 打印方法
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:ai_chat_core/ai_chat_core.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
@@ -7,9 +8,9 @@ class VoiceRecognitionService {
|
||||
Future<String?> recognizeSpeech(List<int> audioBytes,
|
||||
{String lang = 'cn'}) async {
|
||||
try {
|
||||
print('准备发送OPUS音频数据,大小: ${audioBytes.length} 字节');
|
||||
Logger.i('准备发送OPUS音频数据,大小: ${audioBytes.length} 字节');
|
||||
final uri = Uri.parse('http://143.64.185.20:18606/voice');
|
||||
print('发送到: $uri');
|
||||
Logger.i('发送到: $uri');
|
||||
|
||||
final request = http.MultipartRequest('POST', uri);
|
||||
request.files.add(
|
||||
@@ -22,26 +23,26 @@ class VoiceRecognitionService {
|
||||
);
|
||||
request.fields['lang'] = lang; // 根据参数设置语言
|
||||
|
||||
print('发送请求...');
|
||||
Logger.i('发送请求...');
|
||||
final streamResponse = await request.send();
|
||||
print('收到响应,状态码: ${streamResponse.statusCode}');
|
||||
Logger.i('收到响应,状态码: ${streamResponse.statusCode}');
|
||||
|
||||
final response = await http.Response.fromStream(streamResponse);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
print('响应内容: ${response.body}');
|
||||
Logger.i('响应内容: ${response.body}');
|
||||
final text = _parseTextFromJson(response.body);
|
||||
if (text != null) {
|
||||
print('解析出文本: $text');
|
||||
Logger.i('解析出文本: $text');
|
||||
return text; // 返回识别的文本
|
||||
} else {
|
||||
print('解析文本失败');
|
||||
Logger.i('解析文本失败');
|
||||
}
|
||||
} else {
|
||||
print('请求失败,状态码: ${response.statusCode},响应: ${response.body}');
|
||||
Logger.i('请求失败,状态码: ${response.statusCode},响应: ${response.body}');
|
||||
}
|
||||
} catch (e) {
|
||||
print('发送录音到服务器时出错: $e');
|
||||
Logger.i('发送录音到服务器时出错: $e');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -55,7 +56,7 @@ class VoiceRecognitionService {
|
||||
}
|
||||
return null;
|
||||
} catch (e) {
|
||||
print('JSON解析错误: $e, 原始数据: $body');
|
||||
Logger.i('JSON解析错误: $e, 原始数据: $body');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user