Skip to content

Commit

Permalink
尝试混合开发,添加dart端代码
Browse files Browse the repository at this point in the history
  • Loading branch information
xwh817 committed Nov 20, 2019
1 parent 1ed3e8c commit 1f74720
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
25 changes: 25 additions & 0 deletions lib/model/speech_manager.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:flutter/services.dart';

class AsrManager {
static const MethodChannel _channel = const MethodChannel('asr_plugin');

/// 初始化
static Future<String> init() async {
return await _channel.invokeMethod('init');
}

/// 开始录音
static Future<String> start({Map params}) async {
return await _channel.invokeMethod('start', params ?? {});
}

/// 停止录音
static Future<String> stop() async {
return await _channel.invokeMethod('stop');
}

/// 取消录音
static Future<String> cancel() async {
return await _channel.invokeMethod('cancel');
}
}
10 changes: 5 additions & 5 deletions lib/pages/search_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_music_player/dao/music_163.dart';
import 'package:flutter_music_player/model/speech_manager.dart';
import 'package:flutter_music_player/utils/toast_util.dart';
import 'package:flutter_music_player/widget/search_bar.dart';
import 'package:flutter_music_player/widget/song_item_tile.dart';
Expand All @@ -16,12 +17,11 @@ class _SearchPageState extends State<SearchPage> {
String keywords = '';
bool isSearching = false;
final TextEditingController _controller = TextEditingController();
//BaiduSpeechRecognition _speechRecognition = BaiduSpeechRecognition();

@override
void initState() {
super.initState();
//_speechRecognition.init().then((value) => print(value));
AsrManager.init().then((re) => print('AsrManagerinit: $re'));
}

@override
Expand All @@ -33,16 +33,16 @@ class _SearchPageState extends State<SearchPage> {
controller: _controller,
onChanged: (text) => keywords = text,
onSpeechPressed: (){
/* _speechRecognition.start().then((value){
print(value);
AsrManager.start().then((value){
print('Speech result: $value');
if (value.isNotEmpty) {
setState(() {
keywords = value;
});
this._search();
}

}); */
});
},
),
actions: [
Expand Down

0 comments on commit 1f74720

Please sign in to comment.