@@ -24,8 +24,8 @@ android { | |||||
applicationId = "com.example.demo001" | applicationId = "com.example.demo001" | ||||
// You can update the following values to match your application needs. | // You can update the following values to match your application needs. | ||||
// For more information, see: https://flutter.dev/to/review-gradle-config. | // For more information, see: https://flutter.dev/to/review-gradle-config. | ||||
minSdk = flutter.minSdkVersion | |||||
targetSdk = flutter.targetSdkVersion | |||||
minSdk = 24 | |||||
targetSdk = 33 | |||||
versionCode = flutter.versionCode | versionCode = flutter.versionCode | ||||
versionName = flutter.versionName | versionName = flutter.versionName | ||||
} | } | ||||
@@ -1,6 +1,8 @@ | |||||
import 'package:demo001/scenes/HomeScene.dart'; | import 'package:demo001/scenes/HomeScene.dart'; | ||||
import 'package:flutter/material.dart'; | import 'package:flutter/material.dart'; | ||||
import 'scenes/TranslateScene.dart'; | |||||
void main() { | void main() { | ||||
WidgetsFlutterBinding.ensureInitialized(); | WidgetsFlutterBinding.ensureInitialized(); | ||||
runApp(const MyApp()); | runApp(const MyApp()); | ||||
@@ -18,7 +20,7 @@ class MyApp extends StatelessWidget { | |||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), | colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), | ||||
useMaterial3: true, | useMaterial3: true, | ||||
), | ), | ||||
home: const MyHomePage(title: 'Flutter Demo Home Page'), | |||||
home: SoundRecordPage(), | |||||
); | ); | ||||
} | } | ||||
} | } |
@@ -0,0 +1,90 @@ | |||||
import 'package:flutter/material.dart'; | |||||
import 'package:flutter_sound/flutter_sound.dart'; | |||||
import 'package:audioplayers/audioplayers.dart'; | |||||
import 'package:permission_handler/permission_handler.dart'; | |||||
class SoundRecordPage extends StatefulWidget { | |||||
@override | |||||
_SoundRecordPageState createState() => _SoundRecordPageState(); | |||||
} | |||||
class _SoundRecordPageState extends State<SoundRecordPage> { | |||||
FlutterSoundRecorder? _soundRecorder; | |||||
AudioPlayer? _audioPlayer; | |||||
String? _audioFilePath; | |||||
@override | |||||
void initState() { | |||||
super.initState(); | |||||
_soundRecorder = FlutterSoundRecorder(); | |||||
_audioPlayer = AudioPlayer(); | |||||
_requestPermissions(); | |||||
} | |||||
// 请求麦克风权限 | |||||
void _requestPermissions() async { | |||||
await Permission.microphone.request(); | |||||
} | |||||
// 开始录音 | |||||
void _startRecording() async { | |||||
final tempPath = | |||||
'/data/user/0/com.example.flutter_app/cache/recorded_audio.aac'; // 可根据需要调整路径 | |||||
await _soundRecorder?.startRecorder( | |||||
toFile: tempPath, | |||||
codec: Codec.aacADTS, | |||||
); | |||||
setState(() { | |||||
_audioFilePath = tempPath; | |||||
}); | |||||
} | |||||
// 停止录音 | |||||
void _stopRecording() async { | |||||
await _soundRecorder?.stopRecorder(); | |||||
} | |||||
// 播放录音 | |||||
void _playRecording() async { | |||||
if (_audioFilePath != null) { | |||||
await _audioPlayer?.play(DeviceFileSource(_audioFilePath!)); | |||||
} | |||||
} | |||||
@override | |||||
void dispose() { | |||||
_soundRecorder?.closeRecorder(); | |||||
_audioPlayer?.dispose(); | |||||
super.dispose(); | |||||
} | |||||
@override | |||||
Widget build(BuildContext context) { | |||||
return Scaffold( | |||||
appBar: AppBar(title: Text('录音与播放')), | |||||
body: Center( | |||||
child: GestureDetector( | |||||
onTapDown: (details) { | |||||
_startRecording(); // 按下时开始录音 | |||||
}, | |||||
onTapUp: (details) { | |||||
_stopRecording(); // 抬起时停止录音并播放 | |||||
_playRecording(); // 播放录音 | |||||
}, | |||||
child: Container( | |||||
padding: EdgeInsets.all(20), | |||||
decoration: BoxDecoration( | |||||
color: Colors.blue, | |||||
shape: BoxShape.circle, | |||||
), | |||||
child: Icon( | |||||
Icons.mic, | |||||
color: Colors.white, | |||||
size: 50, | |||||
), | |||||
), | |||||
), | |||||
), | |||||
); | |||||
} | |||||
} |
@@ -5,10 +5,12 @@ | |||||
import FlutterMacOS | import FlutterMacOS | ||||
import Foundation | import Foundation | ||||
import audio_session | |||||
import audioplayers_darwin | import audioplayers_darwin | ||||
import path_provider_foundation | import path_provider_foundation | ||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { | ||||
AudioSessionPlugin.register(with: registry.registrar(forPlugin: "AudioSessionPlugin")) | |||||
AudioplayersDarwinPlugin.register(with: registry.registrar(forPlugin: "AudioplayersDarwinPlugin")) | AudioplayersDarwinPlugin.register(with: registry.registrar(forPlugin: "AudioplayersDarwinPlugin")) | ||||
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) | PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) | ||||
} | } |
@@ -9,6 +9,14 @@ packages: | |||||
url: "https://pub.dev" | url: "https://pub.dev" | ||||
source: hosted | source: hosted | ||||
version: "2.11.0" | version: "2.11.0" | ||||
audio_session: | |||||
dependency: transitive | |||||
description: | |||||
name: audio_session | |||||
sha256: b2a26ba8b7efa1790d6460e82971fde3e398cfbe2295df9dea22f3499d2c12a7 | |||||
url: "https://pub.dev" | |||||
source: hosted | |||||
version: "0.1.23" | |||||
audioplayers: | audioplayers: | ||||
dependency: "direct main" | dependency: "direct main" | ||||
description: | description: | ||||
@@ -113,6 +121,14 @@ packages: | |||||
url: "https://pub.dev" | url: "https://pub.dev" | ||||
source: hosted | source: hosted | ||||
version: "1.0.8" | version: "1.0.8" | ||||
etau: | |||||
dependency: transitive | |||||
description: | |||||
name: etau | |||||
sha256: "4b43a615ecceb1de7c5a35f0a159920b4fdb8ce5a33d71d3828a31efedc67572" | |||||
url: "https://pub.dev" | |||||
source: hosted | |||||
version: "0.0.14-alpha.4" | |||||
fake_async: | fake_async: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -158,6 +174,30 @@ packages: | |||||
url: "https://pub.dev" | url: "https://pub.dev" | ||||
source: hosted | source: hosted | ||||
version: "5.0.0" | version: "5.0.0" | ||||
flutter_sound: | |||||
dependency: "direct main" | |||||
description: | |||||
name: flutter_sound | |||||
sha256: "08e375d699d85e1a823e250d4c01596eadd92ddf8918b6825e4f23e4dd97cddb" | |||||
url: "https://pub.dev" | |||||
source: hosted | |||||
version: "9.19.1" | |||||
flutter_sound_platform_interface: | |||||
dependency: transitive | |||||
description: | |||||
name: flutter_sound_platform_interface | |||||
sha256: "07d11ca22b1c2e3ffc7c26f0bb6d869c67cef802ff9832e91c9c5e95a3355f6d" | |||||
url: "https://pub.dev" | |||||
source: hosted | |||||
version: "9.19.1" | |||||
flutter_sound_web: | |||||
dependency: transitive | |||||
description: | |||||
name: flutter_sound_web | |||||
sha256: "6f7a954947c18a5b2c2294ecea639c38c266430f6e30b19473191eebc7ab66bd" | |||||
url: "https://pub.dev" | |||||
source: hosted | |||||
version: "9.19.1" | |||||
flutter_test: | flutter_test: | ||||
dependency: "direct dev" | dependency: "direct dev" | ||||
description: flutter | description: flutter | ||||
@@ -200,6 +240,14 @@ packages: | |||||
url: "https://pub.dev" | url: "https://pub.dev" | ||||
source: hosted | source: hosted | ||||
version: "0.20.1" | version: "0.20.1" | ||||
js: | |||||
dependency: transitive | |||||
description: | |||||
name: js | |||||
sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf | |||||
url: "https://pub.dev" | |||||
source: hosted | |||||
version: "0.7.1" | |||||
leak_tracker: | leak_tracker: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -232,6 +280,14 @@ packages: | |||||
url: "https://pub.dev" | url: "https://pub.dev" | ||||
source: hosted | source: hosted | ||||
version: "5.1.1" | version: "5.1.1" | ||||
logger: | |||||
dependency: transitive | |||||
description: | |||||
name: logger | |||||
sha256: be4b23575aac7ebf01f225a241eb7f6b5641eeaf43c6a8613510fc2f8cf187d1 | |||||
url: "https://pub.dev" | |||||
source: hosted | |||||
version: "2.5.0" | |||||
logging: | logging: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -264,6 +320,14 @@ packages: | |||||
url: "https://pub.dev" | url: "https://pub.dev" | ||||
source: hosted | source: hosted | ||||
version: "1.15.0" | version: "1.15.0" | ||||
nested: | |||||
dependency: transitive | |||||
description: | |||||
name: nested | |||||
sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20" | |||||
url: "https://pub.dev" | |||||
source: hosted | |||||
version: "1.0.0" | |||||
path: | path: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -320,6 +384,54 @@ packages: | |||||
url: "https://pub.dev" | url: "https://pub.dev" | ||||
source: hosted | source: hosted | ||||
version: "2.3.0" | version: "2.3.0" | ||||
permission_handler: | |||||
dependency: "direct main" | |||||
description: | |||||
name: permission_handler | |||||
sha256: "18bf33f7fefbd812f37e72091a15575e72d5318854877e0e4035a24ac1113ecb" | |||||
url: "https://pub.dev" | |||||
source: hosted | |||||
version: "11.3.1" | |||||
permission_handler_android: | |||||
dependency: transitive | |||||
description: | |||||
name: permission_handler_android | |||||
sha256: "71bbecfee799e65aff7c744761a57e817e73b738fedf62ab7afd5593da21f9f1" | |||||
url: "https://pub.dev" | |||||
source: hosted | |||||
version: "12.0.13" | |||||
permission_handler_apple: | |||||
dependency: transitive | |||||
description: | |||||
name: permission_handler_apple | |||||
sha256: e6f6d73b12438ef13e648c4ae56bd106ec60d17e90a59c4545db6781229082a0 | |||||
url: "https://pub.dev" | |||||
source: hosted | |||||
version: "9.4.5" | |||||
permission_handler_html: | |||||
dependency: transitive | |||||
description: | |||||
name: permission_handler_html | |||||
sha256: "38f000e83355abb3392140f6bc3030660cfaef189e1f87824facb76300b4ff24" | |||||
url: "https://pub.dev" | |||||
source: hosted | |||||
version: "0.1.3+5" | |||||
permission_handler_platform_interface: | |||||
dependency: transitive | |||||
description: | |||||
name: permission_handler_platform_interface | |||||
sha256: e9c8eadee926c4532d0305dff94b85bf961f16759c3af791486613152af4b4f9 | |||||
url: "https://pub.dev" | |||||
source: hosted | |||||
version: "4.2.3" | |||||
permission_handler_windows: | |||||
dependency: transitive | |||||
description: | |||||
name: permission_handler_windows | |||||
sha256: "1a790728016f79a41216d88672dbc5df30e686e811ad4e698bfc51f76ad91f1e" | |||||
url: "https://pub.dev" | |||||
source: hosted | |||||
version: "0.2.1" | |||||
platform: | platform: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -336,6 +448,30 @@ packages: | |||||
url: "https://pub.dev" | url: "https://pub.dev" | ||||
source: hosted | source: hosted | ||||
version: "2.1.8" | version: "2.1.8" | ||||
provider: | |||||
dependency: transitive | |||||
description: | |||||
name: provider | |||||
sha256: c8a055ee5ce3fd98d6fc872478b03823ffdb448699c6ebdbbc71d59b596fd48c | |||||
url: "https://pub.dev" | |||||
source: hosted | |||||
version: "6.1.2" | |||||
recase: | |||||
dependency: transitive | |||||
description: | |||||
name: recase | |||||
sha256: e4eb4ec2dcdee52dcf99cb4ceabaffc631d7424ee55e56f280bc039737f89213 | |||||
url: "https://pub.dev" | |||||
source: hosted | |||||
version: "4.1.0" | |||||
rxdart: | |||||
dependency: transitive | |||||
description: | |||||
name: rxdart | |||||
sha256: "5c3004a4a8dbb94bd4bf5412a4def4acdaa12e12f269737a5751369e12d1a962" | |||||
url: "https://pub.dev" | |||||
source: hosted | |||||
version: "0.28.0" | |||||
sky_engine: | sky_engine: | ||||
dependency: transitive | dependency: transitive | ||||
description: flutter | description: flutter | ||||
@@ -389,6 +525,14 @@ packages: | |||||
url: "https://pub.dev" | url: "https://pub.dev" | ||||
source: hosted | source: hosted | ||||
version: "3.3.0+3" | version: "3.3.0+3" | ||||
tau_web: | |||||
dependency: transitive | |||||
description: | |||||
name: tau_web | |||||
sha256: c612cd3dcd9b7aa3472c0272bf3531fc232cd80e53ed7d7388b77dd541720cd6 | |||||
url: "https://pub.dev" | |||||
source: hosted | |||||
version: "0.0.14-alpha.4" | |||||
term_glyph: | term_glyph: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -41,6 +41,8 @@ dependencies: | |||||
go_router: ^14.6.3 | go_router: ^14.6.3 | ||||
audioplayers: ^6.1.0 | audioplayers: ^6.1.0 | ||||
path_provider: ^2.1.5 | path_provider: ^2.1.5 | ||||
flutter_sound: ^9.19.1 | |||||
permission_handler: ^11.3.1 | |||||
dev_dependencies: | dev_dependencies: | ||||
flutter_test: | flutter_test: | ||||
@@ -63,8 +65,6 @@ flutter: | |||||
# included with your application, so that you can use the icons in | # included with your application, so that you can use the icons in | ||||
# the material Icons class. | # the material Icons class. | ||||
uses-material-design: true | uses-material-design: true | ||||
assets: | |||||
- assests/original.pcm | |||||
# To add assets to your application, add an assets section, like this: | # To add assets to your application, add an assets section, like this: | ||||
# assets: | # assets: | ||||
# - images/a_dot_burr.jpeg | # - images/a_dot_burr.jpeg | ||||
@@ -7,8 +7,11 @@ | |||||
#include "generated_plugin_registrant.h" | #include "generated_plugin_registrant.h" | ||||
#include <audioplayers_windows/audioplayers_windows_plugin.h> | #include <audioplayers_windows/audioplayers_windows_plugin.h> | ||||
#include <permission_handler_windows/permission_handler_windows_plugin.h> | |||||
void RegisterPlugins(flutter::PluginRegistry* registry) { | void RegisterPlugins(flutter::PluginRegistry* registry) { | ||||
AudioplayersWindowsPluginRegisterWithRegistrar( | AudioplayersWindowsPluginRegisterWithRegistrar( | ||||
registry->GetRegistrarForPlugin("AudioplayersWindowsPlugin")); | registry->GetRegistrarForPlugin("AudioplayersWindowsPlugin")); | ||||
PermissionHandlerWindowsPluginRegisterWithRegistrar( | |||||
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin")); | |||||
} | } |
@@ -4,6 +4,7 @@ | |||||
list(APPEND FLUTTER_PLUGIN_LIST | list(APPEND FLUTTER_PLUGIN_LIST | ||||
audioplayers_windows | audioplayers_windows | ||||
permission_handler_windows | |||||
) | ) | ||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST | list(APPEND FLUTTER_FFI_PLUGIN_LIST | ||||