mic_stream 0.1.1 copy "mic_stream: ^0.1.1" to clipboard
mic_stream: ^0.1.1 copied to clipboard

outdated

Provides a tool to get the microphone input as Byte Array Stream

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:mic_stream/mic_stream.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  //Stream<List<int>> stream;
  //StreamSubscription<List<int>> listener;

  var stream;
  var listener;

  Icon _icon = Icon(Icons.keyboard_voice);
  Color _iconColor = Colors.white;
  Color _bgColor = Colors.cyan;
  bool isRecording = false;

  @override
  void initState() {
    super.initState();
    initPlatformState();

    print("==== Start Example ====");
  }

  void controlMicStream() async {

    if (!isRecording) {

      print("Start Streaming from the microphone...");
      stream = microphone(audioSource: AudioSource.MIC, sampleRate: 32000, channelConfig: ChannelConfig.CHANNEL_IN_MONO, audioFormat: AudioFormat.ENCODING_PCM_8BIT);
      _updateButton();

      isRecording = true;

      print("Start Listening to the microphone");
      //listener = stream.listen((samples) => samples);
      listener = stream.listen((samples) => print(samples));
    }
    else {
      print("Stop Listening to the microphone");
      listener.cancel();

      isRecording = false;
      print('Stopped listening to the microphone');

      _updateButton();
    }
  }

  void _updateButton() {
    setState(() {
      _bgColor = (isRecording) ? Colors.cyan : Colors.red;
      _icon = (isRecording)  ? Icon(Icons.keyboard_voice) : Icon(Icons.stop);
    });
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    setState(() {});
    if (!mounted) return;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark(),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin: mic_stream :: Debug'),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: (){controlMicStream();},
          child: _icon,
          foregroundColor: _iconColor,
          backgroundColor: _bgColor,
        ),
      ),
    );
  }
}
88
likes
0
pub points
91%
popularity

Publisher

unverified uploader

Provides a tool to get the microphone input as Byte Array Stream

Homepage

License

unknown (LICENSE)

Dependencies

flutter, permission

More

Packages that depend on mic_stream