Introduction
Building voice-enabled apps elevates mobile experiences by allowing hands-free input and real-time transcription. Flutter’s cross-platform framework pairs seamlessly with Google Cloud Speech-to-Text, enabling developers to integrate robust speech recognition into iOS and Android projects. This tutorial walks through authentication, setup, implementing live audio capture, handling recognition results, and optimizing performance—all with code examples in Dart.
Setup and Authentication
First, enable the Speech-to-Text API in your Google Cloud Console and create a service account. Download its JSON key file and store it securely in your project’s root. Then add dependencies in your pubspec.yaml:
dependencies:
flutter:
sdk: flutter
google_speech: ^0.3.0
permission_handler
Run flutter pub get, then import packages:
import 'package:google_speech/google_speech.dart';
import 'package:permission_handler/permission_handler.dart';
Request microphone permission at runtime:
await Permission.microphone.request();
if (!await Permission.microphone.isGranted) {
throw 'Microphone permission required';
}Place your JSON key path in assets and load it at startup:
final serviceAccount = ServiceAccount.fromString(
await rootBundle.loadString('assets/your_key.json')
);
final speechClient = SpeechToText.viaServiceAccount(serviceAccount);Implementing Speech Recognition
With authentication ready, configure streaming recognition. Define your StreamingRecognizeConfig to specify language, encoding, and sample rate:
final config = RecognitionConfig(
encoding: AudioEncoding.LINEAR16,
sampleRateHertz: 16000,
languageCode: 'en-US',
);
final streamingConfig = StreamingRecognitionConfig(
config: config,
interimResults: true,
);
Capture audio via a RecorderStream and bind it to the speech client’s streamingRecognize method:
final recorder = RecorderStream();
await recorder.initialize();
recorder.start();
final responseStream = speechClient.streamingRecognize(
streamingConfig, recorder.audioStream
);
Listening to responseStream yields real-time transcription events.
Processing and Displaying Results
Subscribe to the response stream and update your UI state. Handle both interim and final transcripts:
responseStream.listen((response) {
for (var result in response.results) {
final transcript = result.alternatives.first.transcript;
setState(() {
_text = transcript;
_isFinal = result.isFinal;
});
}
});Display _text in a Text widget. Use _isFinal to style final results differently or trigger actions when the user stops speaking. For example, send a chat message or search query when result.isFinal is true.
Tips for Optimization
• Buffering: Fine-tune sampleRateHertz and buffer duration in RecorderStream to minimize latency.
• Noise reduction: Integrate a pre-processing library or use platform-specific audio APIs to filter background noise.
• Error handling: Listen for onError on the stream to retry or notify users of network issues.
• Resource cleanup: Always call recorder.stop() and responseStream.cancel() in dispose() to free resources.
• Language models: For specialized vocabularies, upload custom language or adaptation models in Cloud Console and reference them in RecognitionConfig.
Vibe Studio

Vibe Studio, powered by Steve’s advanced AI agents, is a revolutionary no-code, conversational platform that empowers users to quickly and efficiently create full-stack Flutter applications integrated seamlessly with Firebase backend services. Ideal for solo founders, startups, and agile engineering teams, Vibe Studio allows users to visually manage and deploy Flutter apps, greatly accelerating the development process. The intuitive conversational interface simplifies complex development tasks, making app creation accessible even for non-coders.
Conclusion
Integrating Google Speech-to-Text in Flutter brings powerful voice capabilities to your mobile app with minimal overhead. By following secure authentication steps, configuring streaming recognition, and handling transcript results effectively, you can build responsive, hands-free interfaces. Optimize latency and accuracy through buffering tweaks and noise reduction. Start experimenting today to enhance accessibility, chatbots, or voice-driven workflows in your next Flutter mobile development project.