### Initialize and Listen for Speech Recognition Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/README.md This is a minimal example demonstrating how to initialize the speech recognition service and start listening for results. Ensure you handle the availability and potential errors during initialization. The `listen` method requires a callback for processing recognized text. ```dart import 'package:speech_to_text/speech_to_text.dart' as stt; stt.SpeechToText speech = stt.SpeechToText(); bool available = await speech.initialize( onStatus: statusListener, onError: errorListener ); if ( available ) { speech.listen( onResult: resultListener ); } else { print("The user has denied the use of speech recognition."); } // some time later... speech.stop() ``` -------------------------------- ### Configuring Installation Directory for Visual Studio Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text_windows/example/windows/CMakeLists.txt Sets up installation directories and ensures the 'install' step is default for Visual Studio builds. ```cmake set(BUILD_BUNDLE_DIR "$") set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Clean and Get Dependencies for macOS Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/README.md Run these commands in the terminal to clean the project, fetch new dependencies, and install pods for macOS. ```bash flutter clean flutter pub get cd macos pod install ``` -------------------------------- ### Define Installation Paths for Bundle Data and Libraries Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/example/windows/CMakeLists.txt Sets the destination directories for installing bundle data and libraries relative to the installation prefix. This organizes the application's runtime files. ```cmake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Install Application Executable Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/example/windows/CMakeLists.txt Installs the main application executable to the specified runtime destination. This makes the application available for execution. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Provider Example Dart File Source: https://github.com/csdcorp/speech_to_text/blob/main/files.txt An example file demonstrating the use of providers in Dart. ```Dart C:\Users\asher\Desktop\repositories\speech_to_text\speech_to_text\example\lib\provider_example.dart ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text_windows/example/windows/CMakeLists.txt Initializes CMake, sets the project name, and specifies the programming language. ```cmake cmake_minimum_required(VERSION 3.14) project(example LANGUAGES CXX) ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/example/windows/CMakeLists.txt Installs any bundled plugin libraries to the application's library directory. This ensures that all necessary plugin components are available at runtime. ```cmake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Set Installation Directory for Visual Studio Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/example/windows/CMakeLists.txt Configures the installation directory for Visual Studio builds to be next to the executable, facilitating in-place running. It also sets the install step as default. ```cmake set(BUILD_BUNDLE_DIR "$") set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() ``` -------------------------------- ### Complete Flutter Speech-to-Text Example Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/README.md This example demonstrates the full integration of the speech-to-text plugin in a Flutter application. It includes initialization, listening, stopping, and displaying recognized words. Ensure the `speech_to_text` and `flutter/material.dart` packages are imported. ```dart import 'package:flutter/material.dart'; import 'package:speech_to_text/speech_recognition_result.dart'; import 'package:speech_to_text/speech_to_text.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', home: MyHomePage(), ); } } class MyHomePage extends StatefulWidget { MyHomePage({Key? key}) : super(key: key); @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State { SpeechToText _speechToText = SpeechToText(); bool _speechEnabled = false; String _lastWords = ''; @override void initState() { super.initState(); _initSpeech(); } /// This has to happen only once per app void _initSpeech() async { _speechEnabled = await _speechToText.initialize(); setState(() {}); } /// Each time to start a speech recognition session void _startListening() async { await _speechToText.listen(onResult: _onSpeechResult); setState(() {}); } /// Manually stop the active speech recognition session /// Note that there are also timeouts that each platform enforces /// and the SpeechToText plugin supports setting timeouts on the /// listen method. void _stopListening() async { await _speechToText.stop(); setState(() {}); } /// This is the callback that the SpeechToText plugin calls when /// the platform returns recognized words. void _onSpeechResult(SpeechRecognitionResult result) { setState(() { _lastWords = result.recognizedWords; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Speech Demo'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( padding: EdgeInsets.all(16), child: Text( 'Recognized words:', style: TextStyle(fontSize: 20.0), ), ), Expanded( child: Container( padding: EdgeInsets.all(16), child: Text( // If listening is active show the recognized words _speechToText.isListening ? '$_lastWords' // If listening isn't active but could be tell the user // how to start it, otherwise indicate that speech // recognition is not yet ready or not supported on // the target device : _speechEnabled ? 'Tap the microphone to start listening...' : 'Speech not available', ), ), ), ], ), ), floatingActionButton: FloatingActionButton( onPressed: // If not yet listening for speech start, otherwise stop _speechToText.isNotListening ? _startListening : _stopListening, tooltip: 'Listen', child: Icon(_speechToText.isNotListening ? Icons.mic_off : Icons.mic), ), ); } } ``` -------------------------------- ### Install Flutter Library Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/example/windows/CMakeLists.txt Installs the main Flutter library file to the bundle's library directory. This is a core component required for the Flutter application to run. ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install AOT Library for Non-Debug Builds Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/example/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library to the data directory, but only for 'Profile' and 'Release' configurations. This optimizes performance for production builds. ```cmake install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/example/windows/CMakeLists.txt Removes existing Flutter assets and then copies the latest assets from the build directory to the application's data directory. This ensures that the application has the most up-to-date assets. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Native Assets Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/example/windows/CMakeLists.txt Copies native assets provided by the build.dart script from all packages to the application's library directory. This ensures that native resources are correctly deployed. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install ICU Data File Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/example/windows/CMakeLists.txt Installs the ICU data file to the bundle's data directory. This file is necessary for internationalization and localization features. ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Set Flutter Library and Headers Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/example/windows/flutter/CMakeLists.txt Defines the Flutter library path and includes necessary header files. These are published to the parent scope for the install step. ```cmake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) list(APPEND FLUTTER_LIBRARY_HEADERS "flutter_export.h" "flutter_windows.h" "flutter_messenger.h" "flutter_plugin_registrar.h" "flutter_texture_registrar.h" ) list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") ``` -------------------------------- ### Link Windows SAPI Libraries Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text_windows/windows/CMakeLists.txt Links essential Windows Speech API (SAPI) libraries for COM, automation, GUIDs, and speech functionality. ```cmake # Link Windows SAPI libraries (without ATL) target_link_libraries(${PLUGIN_NAME} PRIVATE ole32 # For COM oleaut32 # For COM automation uuid # For GUIDs sapi # For Speech API ) ``` -------------------------------- ### Set Project Name and Minimum CMake Version Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/example/windows/CMakeLists.txt Specifies the minimum required CMake version and the project name. This is a standard starting point for CMake projects. ```cmake cmake_minimum_required(VERSION 3.14) project(speech_to_text_example LANGUAGES CXX) ``` -------------------------------- ### iOS Swift Version Error Example Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/README.md This error indicates an incorrect Swift version configuration for the speech_to_text plugin on iOS. Consult the provided GitHub issue for detailed solutions. ```swift /Users/markvandergon/flutter/.pub-cache/hosted/pub.dartlang.org/speech_to_text-1.1.0/ios/Classes/SwiftSpeechToTextPlugin.swift:224:44: error: value of type 'SwiftSpeechToTextPlugin' has no member 'AVAudioSession' rememberedAudioCategory = self.AVAudioSession.Category ~~~~ ^~~~~~~~~~~~~~ /Users/markvandergon/flutter/.pub-cache/hosted/pub.dartlang.org/speech_to_text-1.1.0/ios/Classes/SwiftSpeechToTextPlugin.swift:227:63: error: type 'Int' has no member 'notifyOthersOnDeactivation' try self.audioSession.setActive(true, withFlags: .notifyOthersOnDeactivation) ``` -------------------------------- ### Initialize and Use Speech to Text in Flutter Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/example/README.md This Dart code initializes the speech-to-text plugin, sets up listeners for errors and status updates, and provides UI elements to start, stop, and cancel listening. It displays recognized words and any errors encountered. ```dart import 'package:flutter/material.dart'; import 'dart:async'; import 'package:speech_to_text/speech_to_text.dart'; import 'package:speech_to_text/speech_recognition_result.dart'; import 'package:speech_to_text/speech_recognition_error.dart'; void main() => runApp(MyApp()); class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { bool _hasSpeech = false; String lastWords = ""; String lastError = ""; String lastStatus = ""; final SpeechToText speech = SpeechToText(); @override void initState() { super.initState(); initSpeechState(); } Future initSpeechState() async { bool hasSpeech = await speech.initialize(onError: errorListener, onStatus: statusListener ); if (!mounted) return; setState(() { _hasSpeech = hasSpeech; }); } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: const Text('Speech to Text Example'), ), body: _hasSpeech ? Column(children: [ Expanded( child: Center( child: Text('Speech recognition available'), ), ), Expanded( child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ TextButton( child: Text('Start'), onPressed: startListening, ), TextButton( child: Text('Stop'), onPressed: stopListening, ), TextButton( child: Text('Cancel'), onPressed:cancelListening, ), ], ), ), Expanded( child: Column( children: [ Center( child: Text('Recognized Words'), ), Center( child: Text(lastWords), ), ], ), ), Expanded( child: Column( children: [ Center( child: Text('Error'), ), Center( child: Text(lastError), ), ], ), ), Expanded( child: Center( child: speech.isListening ? Text("I'm listening...") : Text( 'Not listening' ), ), ), ]) : Center( child: Text('Speech recognition unavailable', style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold))), ), ); } void startListening() { lastWords = ""; lastError = ""; speech.listen(onResult: resultListener ); setState(() { }); } void stopListening() { speech.stop( ); setState(() { }); } void cancelListening() { speech.cancel( ); setState(() { }); } void resultListener(SpeechRecognitionResult result) { setState(() { lastWords = "${result.recognizedWords} - ${result.finalResult}"; }); } void errorListener(SpeechRecognitionError error ) { setState(() { lastError = "${error.errorMsg} - ${error.permanent}"; }); } void statusListener(String status ) { setState(() { lastStatus = "$status"; }); } } ``` -------------------------------- ### Main Dart File Source: https://github.com/csdcorp/speech_to_text/blob/main/files.txt The main entry point for the Dart application. ```Dart C:\Users\asher\Desktop\repositories\speech_to_text\speech_to_text\example\lib\main.dart ``` -------------------------------- ### Gradle Wrapper Properties Source: https://github.com/csdcorp/speech_to_text/blob/main/files.txt Configuration file for the Gradle wrapper, specifying the Gradle version to use. ```properties distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https://services.gradle.org/distributions/gradle-7.5.1-bin.zip ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/example/windows/runner/CMakeLists.txt Applies a standard set of build configurations to the target executable. This can be removed if custom build settings are required. ```cmake # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Launch Image Assets Source: https://github.com/csdcorp/speech_to_text/blob/main/files.txt Contains image assets for the application's launch screen, provided in different resolutions. ```Asset Catalog C:\Users\asher\Desktop\repositories\speech_to_text\speech_to_text\example\ios\Runner\Assets.xcassets\LaunchImage.imageset\LaunchImage@2x.png ``` ```Asset Catalog C:\Users\asher\Desktop\repositories\speech_to_text\speech_to_text\example\ios\Runner\Assets.xcassets\LaunchImage.imageset\LaunchImage@3x.png ``` -------------------------------- ### Switch Speech Recognition Language Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/README.md Use the `locales` property to get available languages and the `localeId` parameter in the `listen` method to select a specific language for speech recognition. ```dart var locales = await speech.locales(); // Some UI or other code to select a locale from the list // resulting in an index, selectedLocale var selectedLocale = locales[selectedLocale]; speech.listen( onResult: resultListener, localeId: selectedLocale.localeId, ); ``` -------------------------------- ### Kotlin Main Activity Source: https://github.com/csdcorp/speech_to_text/blob/main/files.txt The main entry point for the Android application, written in Kotlin. This file typically sets up the UI and handles user interactions. ```kotlin package com.csdcorp.speech_to_text import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import com.csdcorp.speech_to_text.ui.theme.Speech_to_textTheme class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { Speech_to_textTheme { // A surface container using the 'background' color from the theme Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) { Greeting("Android") } } } } } @Composable fun Greeting(name: String, modifier: Modifier = Modifier) { Text( text = "Hello $name!", modifier = modifier ) } @Preview(showBackground = true) @Composable fun GreetingPreview() { Speech_to_textTheme { Greeting("Android") } } ``` -------------------------------- ### Gradle Settings Source: https://github.com/csdcorp/speech_to_text/blob/main/files.txt The settings.gradle file configures the build environment for Gradle, including project name and included modules. It's essential for multi-module projects. ```gradle pluginManagement { repositories { google() mavenCentral() gradlePluginPortal() } } depositorees { google() mavenCentral() } rootProject.name = "speech_to_text" include ":app" include ":kotlin" include ":csdcorp" include ":speech_to_text" include ":dart_tool" include ":android" include ":assets" include ":ios" include ":lib" include ":linux" include ":macOs" include ":web" ``` -------------------------------- ### Generated Plugins CMakeLists.txt Source: https://github.com/csdcorp/speech_to_text/blob/main/files.txt CMake build script for generating plugins. ```CMake C:\Users\asher\Desktop\repositories\speech_to_text\speech_to_text\example\linux\flutter\generated_plugins.cmake ``` -------------------------------- ### Android Emulator Speech Recognition Log Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/README.md These log messages indicate a failure in starting the speech recognition service on an Android emulator, even after granting permissions. This often relates to the underlying Google app's status or permissions. ```log D/SpeechToTextPlugin(12555): put partial D/SpeechToTextPlugin(12555): put languageTag D/SpeechToTextPlugin(12555): Error 9 after start at 35 1000.0 / -100.0 D/SpeechToTextPlugin(12555): Cancel listening ``` -------------------------------- ### Define C++ Wrapper Sources Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/example/windows/flutter/CMakeLists.txt Lists the source files for the C++ client wrapper, categorized for core, plugin, and application use. These lists are prepended with the wrapper root directory. ```cmake list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_PLUGIN "plugin_registrar.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") ``` -------------------------------- ### Configure Flutter Tool Backend Custom Command Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/example/windows/flutter/CMakeLists.txt Sets up a custom command to run the Flutter tool backend. A phony output file is used to ensure the command runs every time. This command generates the Flutter library and headers, and wrapper sources. ```cmake set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ${PHONY_OUTPUT} COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" ${FLUTTER_TARGET_PLATFORM} $ VERBATIM ) ``` -------------------------------- ### Apply Standard Flutter Plugin Settings Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text_windows/windows/CMakeLists.txt Applies standard build settings and configurations common to Flutter plugins. ```cmake # Apply standard Flutter plugin settings apply_standard_settings(${PLUGIN_NAME}) ``` -------------------------------- ### Launch Background Drawable Source: https://github.com/csdcorp/speech_to_text/blob/main/files.txt Drawable resource for the launch background in Android. ```xml ``` -------------------------------- ### Define Bundled Libraries Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text_windows/windows/CMakeLists.txt Lists absolute paths to libraries that should be bundled with the plugin. Currently empty. ```cmake # List of absolute paths to libraries that should be bundled with the plugin set(speech_to_text_windows_bundled_libraries "" PARENT_SCOPE ) ``` -------------------------------- ### Configure Project and Plugin Name Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text_windows/windows/CMakeLists.txt Sets the minimum CMake version, project name, and the specific plugin name used for builds. ```cmake cmake_minimum_required(VERSION 3.14) set(PROJECT_NAME "speech_to_text_windows") project(${PROJECT_NAME} LANGUAGES CXX) # This value is used when generating builds using this plugin, so it must not be changed set(PLUGIN_NAME "speech_to_text_windows_plugin") ``` -------------------------------- ### Win32 Window Implementation Source: https://github.com/csdcorp/speech_to_text/blob/main/files.txt Base implementation for a Win32 window. This C++ code provides fundamental window creation and message handling capabilities. ```cpp #include "win32_window.h" #include namespace { // The name of the Flutter channel used for communication. const char kChannelName[] = "speech_to_text_windows"; } Win32Window::Win32Window() = default; Win32Window::~Win32Window() = default; bool Win32Window::Create(const std::wstring& title, const flutter::Size& initial_size) { // Register the window class. window_class_registration_ = std::make_unique(L"io.flutter.window.direct.transparent", [](HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -> LRESULT { return DefWindowProc(hWnd, message, wParam, lParam); }); if (!window_class_registration_->Register()) { return false; } // Create the window. window_handle_ = CreateWindowEx( WS_EX_CLIENTEDGE, window_class_registration_->ClassName().c_str(), title.c_str(), WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, static_cast(initial_size.width), static_cast(initial_size.height), nullptr, nullptr, GetModuleHandle(nullptr), this); if (!window_handle_) { return false; } return true; } void Win32Window::OnResize(UINT width, UINT height) { // No-op by default. } LRESULT Win32Window::MessageHandler(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_DESTROY: { PostQuitMessage(0); return 0; } case WM_SIZE: { UINT width = LOWORD(lParam); UINT height = HIWORD(lParam); OnResize(width, height); break; } default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } Win32Window::WindowClassRegistration::WindowClassRegistration(std::wstring className, WNDPROC proc) : className_(std::move(className)), proc_(proc) {} Win32Window::WindowClassRegistration::~WindowClassRegistration() { // Unregister the window class. UnregisterClass(className_.c_str(), GetModuleHandle(nullptr)); } bool Win32Window::WindowClassRegistration::Register() { WNDCLASS wc = {}; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = proc_; wc.hInstance = GetModuleHandle(nullptr); wc.lpszClassName = className_.c_str(); wc.hCursor = LoadCursor(nullptr, IDC_ARROW); return RegisterClass(&wc) != 0; } ``` -------------------------------- ### Gradle Wrapper Properties Source: https://github.com/csdcorp/speech_to_text/blob/main/files.txt Configuration file for the Gradle Wrapper, specifying the Gradle version to use for the project. This ensures consistent builds across different environments. ```properties distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https://services.gradle.org/distributions/gradle-8.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists ``` -------------------------------- ### Define Plugin Source Files Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text_windows/windows/CMakeLists.txt Appends source and header files specific to the plugin to a list. ```cmake list(APPEND PLUGIN_SOURCES "speech_to_text_windows_plugin.cpp" "speech_to_text_windows_plugin.h" ) ``` -------------------------------- ### Enable Unicode Support Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/example/windows/CMakeLists.txt Adds preprocessor definitions to enable Unicode support for all projects. This ensures proper handling of international characters. ```cmake add_definitions(-DUNICODE -D_UNICODE) ``` -------------------------------- ### Launch Background Drawable v21 Source: https://github.com/csdcorp/speech_to_text/blob/main/files.txt Drawable resource for the launch background, specifically for Android v21 and above. ```xml ``` -------------------------------- ### Register Plugin Source: https://github.com/csdcorp/speech_to_text/blob/main/files.txt This C++ code registers the plugin with the system. It's essential for the plugin to be recognized and loaded. ```cpp #include "generated_plugin_registrar.h" #include void RegisterPlugins(flutter::PluginRegistrar* registrar) { SpeechToTextWindowsPluginCApiRegisterWithRegistrar(registrar->GetRegistrar("speech_to_text_windows")); } ``` -------------------------------- ### Configure Flutter Interface Library Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/example/windows/flutter/CMakeLists.txt Creates an interface library for Flutter, specifying include directories and linking against the Flutter library. It also adds a dependency on flutter_assemble. ```cmake add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Runner Base Project Files Source: https://github.com/csdcorp/speech_to_text/blob/main/files.txt Core project files for the runner application, including storyboard files for launch and main screens. ```Xcode Project C:\Users\asher\Desktop\repositories\speech_to_text\speech_to_text\example\ios\Runner\Base.xcodeproj\LaunchScreen.storyboard ``` ```Xcode Project C:\Users\asher\Desktop\repositories\speech_to_text\speech_to_text\example\ios\Runner\Base.xcodeproj\Main.storyboard ``` -------------------------------- ### Create Static Library for Flutter Wrapper Plugin Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/example/windows/flutter/CMakeLists.txt Builds a static library for the Flutter wrapper plugin, including core and plugin-specific sources. It applies standard build settings, sets visibility to hidden, links against the Flutter library, and specifies include directories. ```cmake add_library(flutter_wrapper_plugin STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ) apply_standard_settings(flutter_wrapper_plugin) set_target_properties(flutter_wrapper_plugin PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(flutter_wrapper_plugin PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) target_include_directories(flutter_wrapper_plugin PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_plugin flutter_assemble) ``` -------------------------------- ### Link Libraries and Include Directories Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/example/windows/runner/CMakeLists.txt Links the necessary Flutter libraries and the application wrapper library. Also adds the source directory to include paths. Application-specific dependencies should be added here. ```cmake # Add dependency libraries and include directories. Add any application-specific # dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Implement SpeechToTextPlatform Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text_platform_interface/README.md Extend SpeechToTextPlatform to provide platform-specific speech-to-text behavior. Set the default instance when registering your plugin. ```dart SpeechToTextPlatform.instance = MyPlatformSpeechToText() ``` -------------------------------- ### Generated Plugin Registrant CC File Source: https://github.com/csdcorp/speech_to_text/blob/main/files.txt C/C++ source file for registering generated plugins. ```C/C++ C:\Users\asher\Desktop\repositories\speech_to_text\speech_to_text\example\linux\flutter\generated_plugin_registrant.cc ``` -------------------------------- ### Runner Main Function Source: https://github.com/csdcorp/speech_to_text/blob/main/files.txt The main entry point for the runner executable. This C++ code initializes the Flutter engine and runs the application. ```cpp #include #include #include #include #include #include #include #include "flutter_window.h" #include "run_loop.h" #include "win32_flutter_window_with_resource.h" int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { // Attach to console when present (e.g., for debugging) if (::GetConsoleWindow() != nullptr) { FILE* newstdin = nullptr; FILE* newstdout = nullptr; FILE* newstderr = nullptr; if (::freopen_s(&newstdin, "CONIN$", "r", stdin) != 0 || ::freopen_s(&newstdout, "CONOUT$", "w", stdout) != 0 || ::freopen_s(&newstderr, "CONOUT$", "w", stderr) != 0) { return -1; } } // Initialize support for loading resources from the binary. flutter::DartProject project(L"packages/speech_to_text_windows/next"); std::vector command_line_arguments; command_line_arguments.push_back(ப்பிக்க_path); command_line_arguments.push_back("--log-level=debug"); flutter::FlutterViewController::ViewFactory view_factory; view_factory.RegisterViewFactory( "sample-view", [hInstance]() -> std::unique_ptr { return std::make_unique(hInstance); }); if (!flutter::EngineInitializer::Initialize(project, command_line_arguments, view_factory)) { return EXIT_FAILURE; } // Ensure the Flutter engine is shut down. // The engine is shut down by default when the last window is destroyed. RunLoop run_loop; return run_loop.Run(); } ``` -------------------------------- ### Create Static Library for Flutter Wrapper App Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/example/windows/flutter/CMakeLists.txt Builds a static library for the Flutter wrapper application, including core and application-specific sources. It applies standard build settings, links against the Flutter library, and specifies include directories. ```cmake add_library(flutter_wrapper_app STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_APP} ) apply_standard_settings(flutter_wrapper_app) target_link_libraries(flutter_wrapper_app PUBLIC flutter) target_include_directories(flutter_wrapper_app PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_app flutter_assemble) ``` -------------------------------- ### Define Interface Include Directories Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text_windows/windows/CMakeLists.txt Specifies include directories that are available for targets linking against this plugin. ```cmake # Include directories target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include" ) ``` -------------------------------- ### Android Manifest Permissions Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/README.md Declare necessary permissions in AndroidManifest.xml for audio recording, internet access, and Bluetooth functionality. ```xml ``` -------------------------------- ### Define Public Include Directories Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text_windows/windows/CMakeLists.txt Makes the current source directory publicly available for include paths. ```cmake # Make sure the plugin headers are available with correct path target_include_directories(${PLUGIN_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}" ) ``` -------------------------------- ### Runner Utilities Source: https://github.com/csdcorp/speech_to_text/blob/main/files.txt Utility functions for the runner, including file loading and message handling. These are helper functions for the main application logic. ```cpp #include "utils.h" #include #include namespace { // The name of the Flutter channel used for communication. const char kChannelName[] = "speech_to_text_windows"; } // A utility function to load a binary file. std::vector LoadBinaryFile(const std::string& path) { std::ifstream file_stream(path.c_str(), std::ios::binary | std::ios::ate); if (!file_stream.is_open()) { return std::vector(); } std::streampos file_size = file_stream.tellg(); file_stream.seekg(0, std::ios::beg); std::vector buffer(file_size); if (!file_stream.read(reinterpret_cast(buffer.data()), file_size)) { return std::vector(); } return buffer; } ``` -------------------------------- ### Main Activity Kotlin Source: https://github.com/csdcorp/speech_to_text/blob/main/files.txt The main activity for the Android application, written in Kotlin. It serves as the entry point for the app. ```kotlin package com.csdcorp.app.audio_player_interaction import io.flutter.embedding.android.FlutterActivity class MainActivity: FlutterActivity() { } ``` -------------------------------- ### Define Preprocessor Macros Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text_windows/windows/CMakeLists.txt Adds essential preprocessor macros for Flutter plugin implementation and Windows compatibility. ```cmake # Define preprocessor macros target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL WIN32_LEAN_AND_MEAN NOMINMAX _CRT_SECURE_NO_WARNINGS # Disable CRT security warnings _WINSOCK_DEPRECATED_NO_WARNINGS # Disable deprecated Winsock warnings ) ``` -------------------------------- ### Opt-in to Modern CMake Behaviors Source: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/example/windows/CMakeLists.txt Explicitly enables modern CMake behaviors to avoid warnings with recent CMake versions. This ensures compatibility and adherence to current best practices. ```cmake cmake_policy(VERSION 3.14...3.25) ``` -------------------------------- ### Win32 Flutter Window with Resource Source: https://github.com/csdcorp/speech_to_text/blob/main/files.txt This C++ code extends the FlutterWindow to load resources from the application's binary. It's used for embedding assets directly within the executable. ```cpp #include "win32_flutter_window_with_resource.h" #include #include "flutter/binary_messenger.h" #include "flutter/method_channel.h" #include "flutter/method_codec.h" #include "flutter/standard_method_codec.h" namespace { // The name of the Flutter channel used for communication. const char kChannelName[] = "speech_to_text_windows"; } Win32FlutterWindowWithResource::Win32FlutterWindowWithResource(HINSTANCE hInstance) : hInstance_(hInstance) {} Win32FlutterWindowWithResource::~Win32FlutterWindowWithResource() = default; bool Win32FlutterWindowWithResource::Create(const std::wstring& title, const flutter::Size& initial_size) { // Register the window class. window_class_registration_ = std::make_unique(L"io.flutter.window.direct.transparent", [](HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -> LRESULT { return DefWindowProc(hWnd, message, wParam, lParam); }); if (!window_class_registration_->Register()) { return false; } // Create the window. if (!Win32Window::Create(title, initial_size)) { return false; } // Create the Flutter view controller. flutter::DartProject project(L"packages/speech_to_text_windows/next"); project.SetEntrypoint("main"); flutter::FlutterViewController::ViewFactory view_factory; view_factory.RegisterViewFactory( "sample-view", [this]() -> std::unique_ptr { return std::make_unique(GetHandle()); }); if (!flutter::EngineInitializer::Initialize(project, {}, view_factory)) { return false; } flutter_view_controller_ = std::make_unique(std::move(project)); if (!flutter_view_controller_) { return false; } // Attach the Flutter view controller to the window. flutter_view_controller_->AttachToWindow(GetHandle()); // Register the plugin. RegisterPlugins(flutter_view_controller_->GetRegistrar("speech_to_text_windows")); return true; } void Win32FlutterWindowWithResource::OnResize(UINT width, UINT height) { Win32Window::OnResize(width, height); if (flutter_view_controller_) { flutter_view_controller_->NotifyWindowSizeChanged(width, height); } } LRESULT Win32FlutterWindowWithResource::MessageHandler(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_DESTROY: { flutter_view_controller_->DetachFromWindow(); flutter_view_controller_.reset(); break; } default: // Default message handler for the window. return Win32Window::MessageHandler(hWnd, message, wParam, lParam); } return 0; } ``` -------------------------------- ### Android App Build Configuration Source: https://github.com/csdcorp/speech_to_text/blob/main/files.txt The main build.gradle file for the Android application. It defines project-level build configurations. ```gradle apply plugin: "com.android.application" apply plugin: "kotlin-android" apply plugin: "kotlin-kapt" android { compileSdkVersion 33 buildToolsVersion "30.0.3" defaultConfig { applicationId "com.csdcorp.app.audio_player_interaction" minSdkVersion 21 targetSdkVersion 33 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } buildFeatures { viewBinding true } } dependencies { implementation "androidx.core:core-ktx:1.9.0" implementation "androidx.appcompat:appcompat:1.6.1" implementation "com.google.android.material:material:1.8.0" implementation "androidx.constraintlayout:constraintlayout:2.1.4" testImplementation "junit:junit:4.13.2" androidTestImplementation "androidx.test.ext:junit:1.1.5" androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1" // Speech-to-Text SDK implementation "com.csdcorp.voicesdk:voicesdk:1.1.0" } ``` -------------------------------- ### Flutter Window Implementation Source: https://github.com/csdcorp/speech_to_text/blob/main/files.txt This C++ code defines the Win32 Flutter window, handling its creation and message loop. It's used by the runner to display the Flutter UI. ```cpp #include "flutter_window.h" #include #include #include "flutter/event_stream_handler.h" #include "flutter/method_channel.h" #include "flutter/method_codec.h" #include "flutter/method_result_channels.h" #include "flutter/standard_method_codec.h" #include "generated_plugin_registrant.h" namespace { // The name of the Flutter channel used for communication. const char kChannelName[] = "speech_to_text_windows"; // A utility function to load a binary file. std::vector LoadBinaryFile(const std::string& path) { std::ifstream file_stream(path.c_str(), std::ios::binary | std::ios::ate); if (!file_stream.is_open()) { return std::vector(); } std::streampos file_size = file_stream.tellg(); file_stream.seekg(0, std::ios::beg); std::vector buffer(file_size); if (!file_stream.read(reinterpret_cast(buffer.data()), file_size)) { return std::vector(); } return buffer; } } FlutterWindow::FlutterWindow(const flutter::Path& path) : path_(path) {} FlutterWindow::~FlutterWindow() = default; bool FlutterWindow::Create(const std::wstring& title, const flutter::Size& initial_size) { // Register the window class. window_class_registration_ = std::make_unique(L"io.flutter.window.direct.transparent", [](HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -> LRESULT { return DefWindowProc(hWnd, message, wParam, lParam); }); if (!window_class_registration_->Register()) { return false; } // Create the window. if (!Win32Window::Create(title, initial_size)) { return false; } // Create the Flutter view controller. flutter::DartProject project(path_.GetExtension()); project.SetEntrypoint("main"); flutter::FlutterViewController::ViewFactory view_factory; view_factory.RegisterViewFactory( "sample-view", [this]() -> std::unique_ptr { return std::make_unique(GetHandle()); }); if (!flutter::EngineInitializer::Initialize(project, {}, view_factory)) { return false; } flutter_view_controller_ = std::make_unique(std::move(project)); if (!flutter_view_controller_) { return false; } // Attach the Flutter view controller to the window. flutter_view_controller_->AttachToWindow(GetHandle()); // Register the plugin. RegisterPlugins(flutter_view_controller_->GetRegistrar("speech_to_text_windows")); return true; } void FlutterWindow::OnResize(UINT width, UINT height) { Win32Window::OnResize(width, height); if (flutter_view_controller_) { flutter_view_controller_->NotifyWindowSizeChanged(width, height); } } LRESULT FlutterWindow::MessageHandler(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_DESTROY: { flutter_view_controller_->DetachFromWindow(); flutter_view_controller_.reset(); break; } default: // Default message handler for the window. return Win32Window::MessageHandler(hWnd, message, wParam, lParam); } return 0; } ``` -------------------------------- ### Android Manifest File Source: https://github.com/csdcorp/speech_to_text/blob/main/files.txt The AndroidManifest.xml file for the application. It declares essential components and permissions. ```xml ```