livekit_noise_filter 0.1.0+hotfix.1
livekit_noise_filter: ^0.1.0+hotfix.1 copied to clipboard
AI Noise Cancellation plugin for Livekit SDK.
example/lib/main.dart
import 'package:flutter/foundation.dart' show kDebugMode;
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:livekit_noise_filter/livekit_noise_filter.dart';
// ignore: depend_on_referenced_packages
import 'package:livekit_client/livekit_client.dart';
import 'package:permission_handler/permission_handler.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _audioFilter = LiveKitNoiseFilter();
Room? _room;
String url = 'your cloud url here';
String token = 'your token here';
@override
void initState() {
super.initState();
initFilters();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initFilters() async {
if (lkPlatformIsMobile()) {
var status = await Permission.microphone.request();
if (status.isPermanentlyDenied) {
if (kDebugMode) {
print('Microphone Permission disabled');
}
}
}
_room = Room(
roomOptions: RoomOptions(
defaultAudioCaptureOptions: AudioCaptureOptions(
processor: _audioFilter,
),
),
);
await _room!.connect(url, token);
await _room!.localParticipant!.setMicrophoneEnabled(true);
}
var bypass = false;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('bypass mode: ${bypass ? 'on' : 'off'}'),
Switch(
// This bool value toggles the switch.
value: bypass,
activeColor: Colors.red,
onChanged: (bool value) {
// This is called when the user toggles the switch.
setState(() {
_audioFilter.setBypass(value);
bypass = value;
});
},
)
],
),
),
),
);
}
}