GithubHelp home page GithubHelp logo

Comments (13)

tuyennvt avatar tuyennvt commented on August 14, 2024
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:speech_to_text/speech_to_text.dart';
import 'package:youtube_player_flutter/youtube_player_flutter.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Demo Speech To Text',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Demo Speech To Text'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: const Padding(
        padding: EdgeInsets.all(16),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            _YoutubePlayerWidget(),
            SizedBox(height: 16),
            _SpeechToTextWidget(),
          ],
        ),
      ),
    );
  }
}

class _YoutubePlayerWidget extends StatelessWidget {
  const _YoutubePlayerWidget();

  @override
  Widget build(BuildContext context) {
    print('_YoutubePlayerWidget build');
    return YoutubePlayer(
      controller: YoutubePlayerController(
        initialVideoId: 'iLnmTe5Q2Qw',
        flags: const YoutubePlayerFlags(
          autoPlay: true,
        ),
      ),
      showVideoProgressIndicator: true,
    );
  }
}

class _SpeechToTextWidget extends StatefulWidget {
  const _SpeechToTextWidget();

  @override
  State<_SpeechToTextWidget> createState() => _SpeechToTextWidgetState();
}

class _SpeechToTextWidgetState extends State<_SpeechToTextWidget> {
  SpeechToText speechToText = SpeechToText();
  bool availableSpeech = false;

  @override
  void initState() {
    super.initState();
    _initSpeechToText();
  }

  Future<void> _initSpeechToText() async {
    final permissionStatus = await Permission.speech.request();
    if (!permissionStatus.isGranted) {
      return;
    }
    availableSpeech = await speechToText.initialize();
    return;
  }

  Future<void> _listenSpeechToText() async {
    if (!availableSpeech) {
      return;
    }
    speechToText.listen(
      onResult: (value) {},
      onSoundLevelChange: (value) {},
      listenMode: ListenMode.search,
    );
  }

  @override
  Widget build(BuildContext context) {
    print('_SpeechToTextWidget build');
    return FilledButton(
      onPressed: () async {
        _listenSpeechToText();
      },
      child: const Text('Speech To Text'),
    );
  }
}

from speech_to_text.

sowens-csd avatar sowens-csd commented on August 14, 2024

YouTube player sounds like a different issue than 374. Because SpeechToText takes over the audio channel while it is listening I can see why YouTube might pause. Do you have start/stop sounds configured in your app?

from speech_to_text.

tuyennvt avatar tuyennvt commented on August 14, 2024

YouTube player sounds like a different issue than 374. Because SpeechToText takes over the audio channel while it is listening I can see why YouTube might pause. Do you have start/stop sounds configured in your app?

I played the video on mute, but the problem is still not resolved. Is this the default behavior when I combine them together?

from speech_to_text.

sowens-csd avatar sowens-csd commented on August 14, 2024

I don't know, I've never tried it. Do you have the start/stop sounds configured? If you do I'd suggest trying it without them. If it still pauses that would tell us something.

from speech_to_text.

tuyennvt avatar tuyennvt commented on August 14, 2024

I don't know, I've never tried it. Do you have the start/stop sounds configured? If you do I'd suggest trying it without them. If it still pauses that would tell us something.

I don't understand. What do you want me to start/stop sound of?

from speech_to_text.

xweng1016 avatar xweng1016 commented on August 14, 2024

Probably same issue here. I'm trying to make a talking app with speech_to_text and then play the response audio with audio player or something, but once I trigger speech_to_text no other sound can be played until I reopen a new simulator, seems like this audio channel issue but I tried all the possible stop and start methods I can and no luck.

YouTube player sounds like a different issue than 374. Because SpeechToText takes over the audio channel while it is listening I can see why YouTube might pause. Do you have start/stop sounds configured in your app?

from speech_to_text.

wamynobe avatar wamynobe commented on August 14, 2024

@sowens-csd When I call speechToText.listen(), It blocks the current playing video in video_player package also.

from speech_to_text.

wamynobe avatar wamynobe commented on August 14, 2024

@xweng1016 Have you found any workaround?

from speech_to_text.

kuberanb avatar kuberanb commented on August 14, 2024

have you got any solution for this , i also want to use speech to text and record the same audio and play in the app when needed

from speech_to_text.

wamynobe avatar wamynobe commented on August 14, 2024

@kuberanb Can you describe more detail about your case?

from speech_to_text.

kuberanb avatar kuberanb commented on August 14, 2024

@wamynobe I want the audio recording and speech_to_text to work simulataneously that is when i click the button the audio should record and store it in storage and get the text from the audio and show it in the screen . When i try to enable both at same time the speech_to_text stops listening so how to fix this , i have also mentioned you in my code

from speech_to_text.

wamynobe avatar wamynobe commented on August 14, 2024

@kuberanb because speech_to_text is running on main thread and so do the audio media. my suggestion is that you should try another way to use speech to text. such as build your own speech to text package. I am working on a new speech to text that is spawned by another thread. You can try this approach.

from speech_to_text.

wamynobe avatar wamynobe commented on August 14, 2024

@kuberanb to reconfirm that the audio resource using by webview or some packages like flutter_video ... conflicted with speech to text audio resource so it will pause audio or even the video.

from speech_to_text.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.