Add Flutter GUI example for VAD with a microphone. (#905)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user