Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
aivoice_plugin
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
王苏进
aivoice_plugin
Commits
e1f79b8e
提交
e1f79b8e
authored
9月 08, 2024
作者:
王苏进
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 实现完成
上级
67d744f6
显示空白字符变更
内嵌
并排
正在显示
15 个修改的文件
包含
243 行增加
和
67 行删除
+243
-67
AivoicePlugin.java
...ain/java/com/yourcompany/aivoiceplugin/AivoicePlugin.java
+28
-1
plugin_integration_test.dart
example/integration_test/plugin_integration_test.dart
+5
-8
project.pbxproj
example/ios/Runner.xcodeproj/project.pbxproj
+3
-4
AppDelegate.swift
example/ios/Runner/AppDelegate.swift
+24
-0
Main.storyboard
example/ios/Runner/Base.lproj/Main.storyboard
+8
-5
Info.plist
example/ios/Runner/Info.plist
+12
-0
main.dart
example/lib/main.dart
+37
-20
AivoicePlugin.m
ios/Classes/AivoicePlugin.m
+48
-5
SettingsHelper.h
ios/Classes/SettingsHelper.h
+15
-0
SettingsHelper.m
ios/Classes/SettingsHelper.m
+4
-11
StreamRecorder.m
ios/Classes/StreamRecorder.m
+5
-5
VoiceAsr.h
ios/Classes/VoiceAsr.h
+18
-0
VoiceAsr.m
ios/Classes/VoiceAsr.m
+27
-3
aivoice_plugin.dart
lib/aivoice_plugin.dart
+9
-0
method_channel_aivoice_plugin.dart
lib/method_channel_aivoice_plugin.dart
+0
-5
没有找到文件。
android/src/main/java/com/yourcompany/aivoiceplugin/AivoicePlugin.java
浏览文件 @
e1f79b8e
...
...
@@ -2,18 +2,26 @@ package com.yourcompany.aivoiceplugin;
import
androidx.annotation.NonNull
;
import
io.flutter.embedding.engine.plugins.FlutterPlugin
;
import
io.flutter.plugin.common.EventChannel
;
import
io.flutter.plugin.common.MethodCall
;
import
io.flutter.plugin.common.MethodChannel
;
import
io.flutter.plugin.common.MethodChannel.MethodCallHandler
;
import
io.flutter.plugin.common.MethodChannel.Result
;
import
java.util.HashMap
;
import
java.util.Map
;
public
class
AivoicePlugin
implements
FlutterPlugin
,
MethodCallHandler
{
public
class
AivoicePlugin
implements
FlutterPlugin
,
MethodCallHandler
,
EventChannel
.
StreamHandler
{
private
MethodChannel
channel
;
private
EventChannel
eventChannel
;
private
EventChannel
.
EventSink
eventSink
;
@Override
public
void
onAttachedToEngine
(
@NonNull
FlutterPluginBinding
flutterPluginBinding
)
{
channel
=
new
MethodChannel
(
flutterPluginBinding
.
getBinaryMessenger
(),
"aivoice_plugin"
);
channel
.
setMethodCallHandler
(
this
);
eventChannel
=
new
EventChannel
(
flutterPluginBinding
.
getBinaryMessenger
(),
"aivoice_plugin/events"
);
eventChannel
.
setStreamHandler
(
this
);
}
@Override
...
...
@@ -40,5 +48,23 @@ public class AivoicePlugin implements FlutterPlugin, MethodCallHandler {
@Override
public
void
onDetachedFromEngine
(
@NonNull
FlutterPluginBinding
binding
)
{
channel
.
setMethodCallHandler
(
null
);
eventChannel
.
setStreamHandler
(
null
);
}
@Override
public
void
onListen
(
Object
arguments
,
EventChannel
.
EventSink
events
)
{
eventSink
=
events
;
}
@Override
public
void
onCancel
(
Object
arguments
)
{
eventSink
=
null
;
}
// 新增的发送 Map<String, dynamic> 方法
private
void
sendMapToFlutter
(
Map
<
String
,
Object
>
message
)
{
if
(
eventSink
!=
null
)
{
eventSink
.
success
(
message
);
}
}
}
\ No newline at end of file
example/integration_test/plugin_integration_test.dart
浏览文件 @
e1f79b8e
...
...
@@ -6,20 +6,17 @@
// For more information about Flutter integration tests, please see
// https://docs.flutter.dev/cookbook/testing/integration/introduction
import
'package:flutter_test/flutter_test.dart'
;
import
'package:integration_test/integration_test.dart'
;
import
'package:aivoice_plugin/aivoice_plugin.dart'
;
void
main
(
)
{
IntegrationTestWidgetsFlutterBinding
.
ensureInitialized
();
testWidgets
(
'getPlatformVersion test'
,
(
WidgetTester
tester
)
async
{
final
AivoicePlugin
plugin
=
AivoicePlugin
();
final
String
?
version
=
await
plugin
.
getPlatformVersion
();
// The version string depends on the host platform running the test, so
// just assert that some non-empty string is returned.
expect
(
version
?.
isNotEmpty
,
true
);
//
final AivoicePlugin plugin = AivoicePlugin();
//
final String? version = await plugin.getPlatformVersion();
//
//
The version string depends on the host platform running the test, so
//
//
just assert that some non-empty string is returned.
//
expect(version?.isNotEmpty, true);
});
}
example/ios/Runner.xcodeproj/project.pbxproj
浏览文件 @
e1f79b8e
...
...
@@ -97,7 +97,6 @@
E774E85DB7E797F8A4A2605C
/* Pods-RunnerTests.release.xcconfig */
,
8BDA28280F6BDBDBFE64ACEF
/* Pods-RunnerTests.profile.xcconfig */
,
);
name
=
Pods
;
path
=
Pods
;
sourceTree
=
"<group>"
;
};
...
...
@@ -471,7 +470,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME
=
AppIcon
;
CLANG_ENABLE_MODULES
=
YES
;
CURRENT_PROJECT_VERSION
=
"$(FLUTTER_BUILD_NUMBER)"
;
DEVELOPMENT_TEAM
=
ZTL5A6WMHV
;
DEVELOPMENT_TEAM
=
RPKZNKHR3T
;
ENABLE_BITCODE
=
NO
;
INFOPLIST_FILE
=
Runner/Info.plist
;
LD_RUNPATH_SEARCH_PATHS
=
(
...
...
@@ -654,7 +653,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME
=
AppIcon
;
CLANG_ENABLE_MODULES
=
YES
;
CURRENT_PROJECT_VERSION
=
"$(FLUTTER_BUILD_NUMBER)"
;
DEVELOPMENT_TEAM
=
ZTL5A6WMHV
;
DEVELOPMENT_TEAM
=
RPKZNKHR3T
;
ENABLE_BITCODE
=
NO
;
INFOPLIST_FILE
=
Runner/Info.plist
;
LD_RUNPATH_SEARCH_PATHS
=
(
...
...
@@ -677,7 +676,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME
=
AppIcon
;
CLANG_ENABLE_MODULES
=
YES
;
CURRENT_PROJECT_VERSION
=
"$(FLUTTER_BUILD_NUMBER)"
;
DEVELOPMENT_TEAM
=
ZTL5A6WMHV
;
DEVELOPMENT_TEAM
=
RPKZNKHR3T
;
ENABLE_BITCODE
=
NO
;
INFOPLIST_FILE
=
Runner/Info.plist
;
LD_RUNPATH_SEARCH_PATHS
=
(
...
...
example/ios/Runner/AppDelegate.swift
浏览文件 @
e1f79b8e
import
UIKit
import
Flutter
import
aivoice_plugin
@UIApplicationMain
@objc
class
AppDelegate
:
FlutterAppDelegate
{
...
...
@@ -8,6 +9,29 @@ import Flutter
didFinishLaunchingWithOptions
launchOptions
:
[
UIApplication
.
LaunchOptionsKey
:
Any
]?
)
->
Bool
{
GeneratedPluginRegistrant
.
register
(
with
:
self
)
let
ret
=
SpeechEngine
.
prepareEnvironment
();
if
ret
{
setupResourceManager
()
}
return
super
.
application
(
application
,
didFinishLaunchingWithOptions
:
launchOptions
)
}
func
setupResourceManager
()
{
let
ins
=
SpeechResourceManager
.
shareInstance
()
ins
.
setAppId
(
SDEF_APPID
)
ins
.
setAppVersion
(
"1.0.0"
)
if
let
documentDirectory
=
FileManager
.
default
.
urls
(
for
:
.
documentDirectory
,
in
:
.
userDomainMask
)
.
first
{
let
modelsPath
=
documentDirectory
.
appendingPathComponent
(
"models"
)
.
path
ins
.
setRootPath
(
modelsPath
)
}
ins
.
setOnlineModelEnable
(
true
)
ins
.
setup
()
}
}
example/ios/Runner/Base.lproj/Main.storyboard
浏览文件 @
e1f79b8e
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document
type=
"com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB"
version=
"3.0"
toolsVersion=
"10117"
systemVersion=
"15F34"
targetRuntime=
"iOS.CocoaTouch"
propertyAccessControl=
"none"
useAutolayout=
"YES"
useTraitCollections=
"YES"
initialViewController=
"BYZ-38-t0r"
>
<?xml version="1.0" encoding="UTF-8"?>
<document
type=
"com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB"
version=
"3.0"
toolsVersion=
"22155"
targetRuntime=
"iOS.CocoaTouch"
propertyAccessControl=
"none"
useAutolayout=
"YES"
useTraitCollections=
"YES"
colorMatched=
"YES"
initialViewController=
"BYZ-38-t0r"
>
<device
id=
"retina6_12"
orientation=
"portrait"
appearance=
"light"
/>
<dependencies>
<deployment
identifier=
"iOS"
/>
<plugIn
identifier=
"com.apple.InterfaceBuilder.IBCocoaTouchPlugin"
version=
"10085"
/>
<plugIn
identifier=
"com.apple.InterfaceBuilder.IBCocoaTouchPlugin"
version=
"22131"
/>
<capability
name=
"documents saved in the Xcode 8 format"
minToolsVersion=
"8.0"
/>
</dependencies>
<scenes>
<!--Flutter View Controller-->
...
...
@@ -14,13 +16,14 @@
<viewControllerLayoutGuide
type=
"bottom"
id=
"wfy-db-euE"
/>
</layoutGuides>
<view
key=
"view"
contentMode=
"scaleToFill"
id=
"8bC-Xf-vdC"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"
600"
height=
"600
"
/>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"
393"
height=
"852
"
/>
<autoresizingMask
key=
"autoresizingMask"
widthSizable=
"YES"
heightSizable=
"YES"
/>
<color
key=
"backgroundColor"
white=
"1"
alpha=
"1"
colorSpace=
"custom"
customColorSpace=
"calibratedWhite
"
/>
<color
key=
"backgroundColor"
red=
"1"
green=
"1"
blue=
"1"
alpha=
"1"
colorSpace=
"custom"
customColorSpace=
"sRGB
"
/>
</view>
</viewController>
<placeholder
placeholderIdentifier=
"IBFirstResponder"
id=
"dkx-z0-nzr"
sceneMemberID=
"firstResponder"
/>
</objects>
<point
key=
"canvasLocation"
x=
"-16"
y=
"-40"
/>
</scene>
</scenes>
</document>
example/ios/Runner/Info.plist
浏览文件 @
e1f79b8e
...
...
@@ -45,5 +45,17 @@
<
tru
e
/
>
<
k
e
y
>
UIApplicationSupportsIndirectInputEvents
<
/k
e
y
>
<
tru
e
/
>
<
k
e
y
>
UIBackgroundModes
<
/k
e
y
>
<
a
rr
a
y
>
<
string
>
audio
<
/string
>
<
/
a
rr
a
y
>
<
k
e
y
>
NSMicrophoneUsageDescription
<
/k
e
y
>
<
string
>
Speech
demo
would
like
to
access
your
recorder
data.
<
/string
>
<
k
e
y
>
UIFileSharingEnabled
<
/k
e
y
>
<
tru
e
/
>
<
k
e
y
>
UIRequiredDeviceCapabilities
<
/k
e
y
>
<
a
rr
a
y
>
<
string
>
armv7
<
/string
>
<
/
a
rr
a
y
>
<
/
d
i
c
t
>
<
/plist
>
example/lib/main.dart
浏览文件 @
e1f79b8e
import
'package:flutter/material.dart'
;
import
'dart:async'
;
import
'package:flutter/services.dart'
;
import
'package:aivoice_plugin/aivoice_plugin.dart'
;
import
'package:flutter/material.dart'
;
void
main
(
)
{
runApp
(
const
MyApp
());
...
...
@@ -16,35 +15,30 @@ class MyApp extends StatefulWidget {
}
class
_MyAppState
extends
State
<
MyApp
>
{
String
_platformVersion
=
'Unknown'
;
final
String
_platformVersion
=
'Unknown'
;
final
_aivoicePlugin
=
AivoicePlugin
();
String
_text
=
''
;
@override
void
initState
()
{
super
.
initState
();
initPlatformState
();
_aivoicePlugin
.
onAsrResultReceived
.
listen
((
event
)
{
setState
(()
{
_text
=
event
[
"text"
];
});
// print(event["text"]);
});
// _aivoicePlugin.initEngine({});
}
// Platform messages are asynchronous, so we initialize in an async method.
Future
<
void
>
initPlatformState
()
async
{
String
platformVersion
;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try
{
platformVersion
=
await
_aivoicePlugin
.
getPlatformVersion
()
??
'Unknown platform version'
;
}
on
PlatformException
{
platformVersion
=
'Failed to get platform version.'
;
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if
(!
mounted
)
return
;
setState
(()
{
_platformVersion
=
platformVersion
;
});
setState
(()
{});
}
@override
...
...
@@ -55,7 +49,30 @@ class _MyAppState extends State<MyApp> {
title:
const
Text
(
'Plugin example app'
),
),
body:
Center
(
child:
Text
(
'Running on:
$_platformVersion
\n
'
),
child:
Row
(
children:
[
Expanded
(
child:
Text
(
'识别结果是:
$_text
'
)),
],
),
),
floatingActionButton:
Row
(
children:
[
TextButton
(
onPressed:
()
{
_aivoicePlugin
.
initEngine
({});
},
child:
const
Text
(
'init'
)),
TextButton
(
onPressed:
()
{
_aivoicePlugin
.
startOrStopEngine
(
true
);
},
child:
const
Text
(
'start'
)),
TextButton
(
onPressed:
()
{
_aivoicePlugin
.
stopEngine
();
},
child:
const
Text
(
'stop'
)),
],
),
),
);
...
...
ios/Classes/AivoicePlugin.m
浏览文件 @
e1f79b8e
#import "AivoicePlugin.h"
#import "VoiceAsr.h"
@interface
AivoicePlugin
()
@interface
AivoicePlugin
()
<
FlutterStreamHandler
,
VoiceAsrDelegate
>
@property
(
nonatomic
,
strong
)
FlutterEventSink
eventSink
;
@property
(
nonatomic
,
strong
)
VoiceAsr
*
voiceAsr
;
@end
@implementation
AivoicePlugin
...
...
@@ -11,26 +14,66 @@
binaryMessenger
:[
registrar
messenger
]];
AivoicePlugin
*
instance
=
[[
AivoicePlugin
alloc
]
init
];
[
registrar
addMethodCallDelegate
:
instance
channel
:
channel
];
FlutterEventChannel
*
eventChannel
=
[
FlutterEventChannel
eventChannelWithName
:
@"aivoice_plugin/events"
binaryMessenger
:[
registrar
messenger
]];
[
eventChannel
setStreamHandler
:
instance
];
}
-
(
void
)
handleMethodCall
:(
FlutterMethodCall
*
)
call
result
:(
FlutterResult
)
result
{
// 删除了 getPlatformVersion 方法的实现
if
([
@"initEngine"
isEqualToString
:
call
.
method
])
{
// 空实现
[
self
.
voiceAsr
initEngine
];
result
(
nil
);
}
else
if
([
@"stopEngine"
isEqualToString
:
call
.
method
])
{
// 空实现
[
self
.
voiceAsr
stopEngineBtnClicked
];
result
(
nil
);
}
else
if
([
@"uninitEngine"
isEqualToString
:
call
.
method
])
{
// 空实现
[
self
.
voiceAsr
uninitEngine
];
result
(
nil
);
}
else
if
([
@"startOrStopEngine"
isEqualToString
:
call
.
method
])
{
// 空实现
// BOOL arg = [NSNumber numberWithBool:call.arguments];
[
self
.
voiceAsr
startEngineBtnClicked
];
result
(
nil
);
}
else
{
result
(
FlutterMethodNotImplemented
);
}
}
-
(
FlutterError
*
_Nullable
)
onListenWithArguments
:(
id
_Nullable
)
arguments
eventSink
:(
FlutterEventSink
)
events
{
self
.
eventSink
=
events
;
return
nil
;
}
-
(
FlutterError
*
_Nullable
)
onCancelWithArguments
:(
id
_Nullable
)
arguments
{
self
.
eventSink
=
nil
;
return
nil
;
}
// 新增的发送 Map<String, dynamic> 方法
-
(
void
)
sendMessageToFlutter
:(
NSDictionary
*
)
message
{
if
(
self
.
eventSink
)
{
self
.
eventSink
(
message
);
}
}
-
(
VoiceAsr
*
)
voiceAsr
{
if
(
!
_voiceAsr
)
{
_voiceAsr
=
[[
VoiceAsr
alloc
]
initWithDelegate
:
self
];
}
return
_voiceAsr
;
}
-
(
void
)
onRecieve
:
(
nonnull
NSDictionary
*
)
message
{
[
self
sendMessageToFlutter
:
message
];
}
@end
ios/Classes/SettingsHelper.h
浏览文件 @
e1f79b8e
...
...
@@ -151,8 +151,20 @@ extern NSString *const SETTING_AU_PROCESS_TIMEOUT;
extern
NSString
*
const
SETTING_AU_AUDIO_PACKET_DURATION
;
extern
NSString
*
const
SETTING_AU_EMPTY_PACKET_INTERVAL
;
#pragma mark - SETTING_HELPER
@interface
SettingsHelper
:
NSObject
@property
(
strong
,
nonatomic
)
Settings
*
asrSettings
;
@property
(
strong
,
nonatomic
)
Settings
*
asrOfflineSettings
;
@property
(
strong
,
nonatomic
)
Settings
*
captSettings
;
@property
(
strong
,
nonatomic
)
Settings
*
fulllinkSettings
;
@property
(
strong
,
nonatomic
)
Settings
*
ttsSettings
;
@property
(
strong
,
nonatomic
)
Settings
*
voiceCloneSettings
;
@property
(
strong
,
nonatomic
)
Settings
*
voiceConvSettings
;
@property
(
strong
,
nonatomic
)
Settings
*
dialogSettings
;
@property
(
strong
,
nonatomic
)
Settings
*
vadSettings
;
@property
(
strong
,
nonatomic
)
Settings
*
auSettings
;
+
(
instancetype
)
shareInstance
;
...
...
@@ -160,4 +172,7 @@ extern NSString *const SETTING_AU_EMPTY_PACKET_INTERVAL;
@end
NS_ASSUME_NONNULL_END
ios/Classes/SettingsHelper.m
浏览文件 @
e1f79b8e
...
...
@@ -12,20 +12,11 @@
#import "SensitiveDefines.h"
@interface
SettingsHelper
()
@property
(
strong
,
nonatomic
)
Settings
*
asrSettings
;
@property
(
strong
,
nonatomic
)
Settings
*
asrOfflineSettings
;
@property
(
strong
,
nonatomic
)
Settings
*
captSettings
;
@property
(
strong
,
nonatomic
)
Settings
*
fulllinkSettings
;
@property
(
strong
,
nonatomic
)
Settings
*
ttsSettings
;
@property
(
strong
,
nonatomic
)
Settings
*
voiceCloneSettings
;
@property
(
strong
,
nonatomic
)
Settings
*
voiceConvSettings
;
@property
(
strong
,
nonatomic
)
Settings
*
dialogSettings
;
@property
(
strong
,
nonatomic
)
Settings
*
vadSettings
;
@property
(
strong
,
nonatomic
)
Settings
*
auSettings
;
@end
@implementation
SettingsHelper
#pragma mark - SETTING_KEY
...
...
@@ -515,4 +506,6 @@ static NSArray* SETTING_OPTIONS_AU_ABILITY(void) {
@end
ios/Classes/StreamRecorder.m
浏览文件 @
e1f79b8e
...
...
@@ -7,7 +7,7 @@
//
#import "StreamRecorder.h"
#import "SettingsHelper.h"
//
#import "SettingsHelper.h"
#import <AVFoundation/AVFoundation.h>
#define INPUT_BUS 1
...
...
@@ -20,7 +20,7 @@
@property
(
assign
,
nonatomic
)
BOOL
initted
;
@property
(
weak
,
nonatomic
)
SpeechEngine
*
curEngine
;
@property
(
weak
,
nonatomic
)
NSString
*
curViewId
;
//
@property (weak, nonatomic) NSString *curViewId;
@property
(
assign
,
atomic
)
int16_t
*
packageData
;
@property
(
assign
,
nonatomic
)
int
packageSize
;
// Size in int16_t
@property
(
assign
,
nonatomic
)
int
packageTotalSize
;
// Size in int16_t
...
...
@@ -56,7 +56,7 @@ AudioUnit audioUnit;
}
-
(
void
)
setSpeechEngine
:
(
NSString
*
)
viewId
engine
:
(
SpeechEngine
*
)
engine
{
self
.
curViewId
=
viewId
;
//
self.curViewId = viewId;
self
.
curEngine
=
engine
;
}
...
...
@@ -65,8 +65,8 @@ AudioUnit audioUnit;
return
FALSE
;
}
@synchronized
(
self
)
{
Settings
*
settings
=
[[
SettingsHelper
shareInstance
]
getSettings
:
self
.
curViewId
];
self
.
packageDuration
=
[
settings
getInt
:
SETTING_STREAM_PACKAGE_DURATION
def
:
DEFAULT_PACKAGE_DURATION
]
;
//
Settings *settings = [[SettingsHelper shareInstance]getSettings:self.curViewId];
self
.
packageDuration
=
DEFAULT_PACKAGE_DURATION
;
self
.
packageTotalSize
=
(
int
)((
long
)
REC_SAMPLE_RATE
*
REC_CHANNEL
*
16
/
8
*
self
.
packageDuration
/
1000
/
sizeof
(
int16_t
));
self
.
packageData
=
(
int16_t
*
)
malloc
(
self
.
packageTotalSize
*
sizeof
(
int16_t
));
self
.
packageSize
=
0
;
...
...
ios/Classes/VoiceAsr.h
浏览文件 @
e1f79b8e
...
...
@@ -9,8 +9,26 @@
NS_ASSUME_NONNULL_BEGIN
@protocol
VoiceAsrDelegate
<
NSObject
>
-
(
void
)
onRecieve
:
(
NSDictionary
*
)
message
;
@end
@interface
VoiceAsr
:
NSObject
-
(
instancetype
)
initWithDelegate
:(
id
<
VoiceAsrDelegate
>
)
delegate
;
-
(
void
)
initEngine
;
-
(
void
)
uninitEngine
;
-
(
void
)
startEngineBtnClicked
;
-
(
void
)
stopEngineBtnClicked
;
-
(
void
)
startEngineByLongPress
:(
BOOL
)
isBegin
;
@end
NS_ASSUME_NONNULL_END
ios/Classes/VoiceAsr.m
浏览文件 @
e1f79b8e
...
...
@@ -31,17 +31,36 @@
@property
(
strong
,
nonatomic
)
Settings
*
settings
;
// APP 层自定义的录音机,在音频来源为 Stream 时使用
@property
(
weak
,
nonatomic
)
StreamRecorder
*
streamRecorder
;
@property
(
strong
,
nonatomic
)
StreamRecorder
*
streamRecorder
;
// 一些用于统计的字段
@property
(
nonatomic
,
assign
)
long
talkingFinisheTimestamp
;
@property
(
nonatomic
,
weak
)
id
<
VoiceAsrDelegate
>
delegate
;
@end
@implementation
VoiceAsr
-
(
instancetype
)
init
{
return
[
self
initWithDelegate
:
nil
];
}
-
(
instancetype
)
initWithDelegate
:
(
id
<
VoiceAsrDelegate
>
)
delegate
{
self
=
[
super
init
];
if
(
self
)
{
self
.
delegate
=
delegate
;
self
.
streamRecorder
=
[[
StreamRecorder
alloc
]
init
];
self
.
settings
=
[
SettingsHelper
shareInstance
].
asrSettings
;
}
return
self
;
}
#pragma mark - UI Actions
...
...
@@ -49,6 +68,7 @@
-
(
void
)
startEngineBtnClicked
{
[
self
setResultText
:
@""
];
NSLog
(
@"配置启动参数"
);
[
self
configStartAsrParams
];
...
...
@@ -73,7 +93,7 @@
[
self
.
curEngine
sendDirective
:
SEDirectiveStopEngine
];
}
-
(
void
)
startEngineByLongPress
:
(
bool
)
isBegin
{
-
(
void
)
startEngineByLongPress
:
(
BOOL
)
isBegin
{
if
(
isBegin
)
{
[
self
setResultText
:
@""
];
...
...
@@ -414,6 +434,9 @@
[
text
appendFormat
:
@"
\n
reqid: %@"
,
[
jsonResult
objectForKey
:
@"reqid"
]];
[
text
appendFormat
:
@"
\n
response_delay: %ld"
,
response_delay
];
}
if
([
self
.
delegate
respondsToSelector
:
@selector
(
onRecieve
:)])
{
[
self
.
delegate
onRecieve
:@{
@"text"
:
[
text
stringByTrimmingCharactersInSet
:[
NSCharacterSet
whitespaceCharacterSet
]],
@"isFinal"
:
@
(
isFinal
)}];
}
[
self
setResultText
:[
text
stringByTrimmingCharactersInSet
:[
NSCharacterSet
whitespaceCharacterSet
]]];
});
}
...
...
@@ -440,6 +463,7 @@
#pragma mark - Helper
-
(
NSString
*
)
getRecorderType
{
SettingOptions
*
recorderTypeOptions
=
[
self
.
settings
getOptions
:
SETTING_RECORD_TYPE
];
switch
(
recorderTypeOptions
.
chooseIdx
)
{
case
0
:
...
...
@@ -451,7 +475,7 @@
default
:
break
;
}
return
@""
;
return
SE_RECORDER_TYPE_STREAM
;
}
-
(
void
)
setResultText
:
(
NSString
*
)
result
{
...
...
lib/aivoice_plugin.dart
浏览文件 @
e1f79b8e
import
'package:flutter/services.dart'
;
import
'aivoice_plugin_platform_interface.dart'
;
class
AivoicePlugin
{
...
...
@@ -22,4 +24,11 @@ class AivoicePlugin {
Future
<
void
>
startOrStopEngine
(
bool
isBegin
)
{
return
AivoicePluginPlatform
.
instance
.
startOrStopEngine
(
isBegin
);
}
// 新增的监听方法
static
const
EventChannel
_eventChannel
=
EventChannel
(
'aivoice_plugin/events'
);
Stream
<
Map
<
String
,
dynamic
>>
get
onAsrResultReceived
{
return
_eventChannel
.
receiveBroadcastStream
().
map
((
event
)
=>
Map
<
String
,
dynamic
>.
from
(
event
));
}
}
lib/method_channel_aivoice_plugin.dart
浏览文件 @
e1f79b8e
...
...
@@ -6,11 +6,6 @@ class MethodChannelAivoicePlugin extends AivoicePluginPlatform {
final
MethodChannel
_channel
=
const
MethodChannel
(
'aivoice_plugin'
);
@override
Future
<
String
?>
getPlatformVersion
()
{
return
_channel
.
invokeMethod
<
String
>(
'getPlatformVersion'
);
}
@override
Future
<
void
>
initEngine
(
Map
<
String
,
dynamic
>
config
)
{
return
_channel
.
invokeMethod
<
void
>(
'initEngine'
,
config
);
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论