Add Flutter GUI example for VAD with a microphone. (#905)

This commit is contained in:
Fangjun Kuang
2024-05-24 23:48:12 +08:00
committed by GitHub
parent 4fc0a1dc64
commit 49ea59d4ff
44 changed files with 2289 additions and 115 deletions

View File

@@ -2,6 +2,7 @@
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'dart:typed_data';
import "dart:io";
// Copy the asset file from src to dst
@@ -16,3 +17,16 @@ Future<String> copyAssetFile({required String src, required String dst}) async {
return target;
}
Float32List convertBytesToFloat32(Uint8List bytes, [endian = Endian.little]) {
final values = Float32List(bytes.length ~/ 2);
final data = ByteData.view(bytes.buffer);
for (var i = 0; i < bytes.length; i += 2) {
int short = data.getInt16(i, endian);
values[i ~/ 2] = short / 32678.0;
}
return values;
}