临时更新
This commit is contained in:
parent
22fc80dd07
commit
2606d0144f
@ -108,7 +108,7 @@ class VoiceController(
|
|||||||
currentEnvBaseline = stateManager.currentEnvBaseline
|
currentEnvBaseline = stateManager.currentEnvBaseline
|
||||||
)
|
)
|
||||||
stateManager.isNoisyEnvironment = stateManager.currentEnvBaseline >= VoiceConfig.NOISE_BASELINE_THRESHOLD
|
stateManager.isNoisyEnvironment = stateManager.currentEnvBaseline >= VoiceConfig.NOISE_BASELINE_THRESHOLD
|
||||||
LogUtils.d(VoiceConfig.TAG, "📊 环境状态 | 基线: ${stateManager.currentEnvBaseline} | 嘈杂环境: ${stateManager.isNoisyEnvironment}")
|
// LogUtils.d(VoiceConfig.TAG, "📊 环境状态 | 基线: ${stateManager.currentEnvBaseline} | 嘈杂环境: ${stateManager.isNoisyEnvironment}")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 状态分发
|
// 状态分发
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import android.os.Bundle
|
|||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
|
import android.util.Base64
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
@ -36,6 +37,7 @@ import com.zs.smarthuman.BuildConfig
|
|||||||
import com.zs.smarthuman.R
|
import com.zs.smarthuman.R
|
||||||
import com.zs.smarthuman.base.BaseActivity
|
import com.zs.smarthuman.base.BaseActivity
|
||||||
import com.zs.smarthuman.base.BaseViewModelActivity
|
import com.zs.smarthuman.base.BaseViewModelActivity
|
||||||
|
import com.zs.smarthuman.bean.AudioDTO
|
||||||
import com.zs.smarthuman.bean.NetworkStatusEventMsg
|
import com.zs.smarthuman.bean.NetworkStatusEventMsg
|
||||||
import com.zs.smarthuman.bean.UserInfoResp
|
import com.zs.smarthuman.bean.UserInfoResp
|
||||||
import com.zs.smarthuman.bean.VersionUpdateResp
|
import com.zs.smarthuman.bean.VersionUpdateResp
|
||||||
@ -54,6 +56,7 @@ import com.zs.smarthuman.utils.AudioPcmUtil
|
|||||||
import com.zs.smarthuman.utils.DangerousUtils
|
import com.zs.smarthuman.utils.DangerousUtils
|
||||||
import com.zs.smarthuman.utils.LogFileUtils
|
import com.zs.smarthuman.utils.LogFileUtils
|
||||||
|
|
||||||
|
|
||||||
import com.zs.smarthuman.utils.UnityPlayerHolder
|
import com.zs.smarthuman.utils.UnityPlayerHolder
|
||||||
import com.zs.smarthuman.utils.ViewSlideAnimator
|
import com.zs.smarthuman.utils.ViewSlideAnimator
|
||||||
import com.zs.smarthuman.viewmodel.MainViewModel
|
import com.zs.smarthuman.viewmodel.MainViewModel
|
||||||
@ -151,7 +154,7 @@ class MainActivity : BaseViewModelActivity<ActivityMainBinding, MainViewModel>()
|
|||||||
}
|
}
|
||||||
|
|
||||||
is ApiResult.Success<String> -> {
|
is ApiResult.Success<String> -> {
|
||||||
if (!TextUtils.isEmpty(it.data)){
|
if (!TextUtils.isEmpty(it.data)) {
|
||||||
Toaster.showShort(it.data)
|
Toaster.showShort(it.data)
|
||||||
}
|
}
|
||||||
Toaster.showShort(it)
|
Toaster.showShort(it)
|
||||||
@ -189,16 +192,13 @@ class MainActivity : BaseViewModelActivity<ActivityMainBinding, MainViewModel>()
|
|||||||
assetManager = assets,
|
assetManager = assets,
|
||||||
onWakeup = {
|
onWakeup = {
|
||||||
//每次唤醒前都要把前面的音频停掉
|
//每次唤醒前都要把前面的音频停掉
|
||||||
|
if (backPlaying){
|
||||||
|
mViewModel?.pauseVoice()
|
||||||
|
}
|
||||||
UnityPlayerHolder.getInstance().cancelPCM()
|
UnityPlayerHolder.getInstance().cancelPCM()
|
||||||
UnityPlayerHolder.getInstance()
|
UnityPlayerHolder.getInstance()
|
||||||
.sendVoiceToUnity(
|
.sendVoiceToUnity(
|
||||||
voiceInfo = mutableListOf<VoiceBeanResp>().apply {
|
"https://static.seerteach.net/aidialogue/userWakeUpAudio/344.mp3"
|
||||||
add(
|
|
||||||
VoiceBeanResp(
|
|
||||||
audioUrl = "https://static.seerteach.net/aidialogue/userWakeUpAudio/344.mp3"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
startPlayTimeoutJob?.cancel()
|
startPlayTimeoutJob?.cancel()
|
||||||
@ -208,18 +208,17 @@ class MainActivity : BaseViewModelActivity<ActivityMainBinding, MainViewModel>()
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onFinalAudio = { audio ->
|
onFinalAudio = { audio ->
|
||||||
Log.d("lrsxx", "检测到语音,长度=${audio.size}")
|
|
||||||
mViewModel?.uploadVoice(
|
mViewModel?.uploadVoice(
|
||||||
AudioPcmUtil.pcm16ToBase64(AudioPcmUtil.floatToPcm16(audio)),
|
AudioPcmUtil.pcm16ToBase64(AudioPcmUtil.floatToPcm16(audio)),
|
||||||
1
|
1
|
||||||
)
|
)
|
||||||
// loadLocalJsonAndPlay()
|
// loadLocalJsonAndPlay()
|
||||||
val file = File(
|
// val file = File(
|
||||||
getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)!!.getAbsolutePath(),
|
// getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)!!.getAbsolutePath(),
|
||||||
"xxx.wav"
|
// "xxx.wav"
|
||||||
)
|
// )
|
||||||
AudioDebugUtil.saveFloatPcmAsWav(audio, file)
|
// AudioDebugUtil.saveFloatPcmAsWav(audio, file)
|
||||||
LogUtils.dTag("audioxx", "WAV saved: ${file.path}, samples=${audio.size}")
|
// LogUtils.dTag("audioxx", "WAV saved: ${file.path}, samples=${audio.size}")
|
||||||
lifecycleScope.launch(Dispatchers.Main) {
|
lifecycleScope.launch(Dispatchers.Main) {
|
||||||
|
|
||||||
mVerticalAnimator?.show()
|
mVerticalAnimator?.show()
|
||||||
@ -228,11 +227,12 @@ class MainActivity : BaseViewModelActivity<ActivityMainBinding, MainViewModel>()
|
|||||||
onStateChanged = { state ->
|
onStateChanged = { state ->
|
||||||
|
|
||||||
},
|
},
|
||||||
onTimeoutTip = {timeoutType->
|
onTimeoutTip = { timeoutType ->
|
||||||
when(timeoutType){
|
when (timeoutType) {
|
||||||
TimeoutType.IDLE_TIMEOUT -> {//闲时超时
|
TimeoutType.IDLE_TIMEOUT -> {//闲时超时
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TimeoutType.INVALID_SPEECH_TIMEOUT -> {//无效语音后超时
|
TimeoutType.INVALID_SPEECH_TIMEOUT -> {//无效语音后超时
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -241,28 +241,26 @@ class MainActivity : BaseViewModelActivity<ActivityMainBinding, MainViewModel>()
|
|||||||
mVerticalAnimator?.hide()
|
mVerticalAnimator?.hide()
|
||||||
UnityPlayerHolder.getInstance()
|
UnityPlayerHolder.getInstance()
|
||||||
.sendVoiceToUnity(
|
.sendVoiceToUnity(
|
||||||
voiceInfo = mutableListOf<VoiceBeanResp>().apply {
|
UserInfoManager.userInfo?.endAudioUrl ?: ""
|
||||||
add(
|
|
||||||
VoiceBeanResp(
|
|
||||||
audioUrl = UserInfoManager.userInfo?.endAudioUrl?:""
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun receivedIMMsg(msg: SingleMessage) {
|
override fun receivedIMMsg(msg: SingleMessage) {
|
||||||
when (msg.msgContentType) {
|
when (msg.msgContentType) {
|
||||||
MessageContentType.RECEIVE_VOICE_STREAM.msgContentType -> {
|
MessageContentType.RECEIVE_VOICE_STREAM.msgContentType -> {
|
||||||
|
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
|
||||||
|
|
||||||
// LogFileUtils.logToFile2(this@MainActivity,msg.content)
|
// LogFileUtils.logToFile2(this@MainActivity,msg.content)
|
||||||
UnityPlayerHolder.getInstance()
|
UnityPlayerHolder.getInstance()
|
||||||
.startTalking(msg.content)
|
.startTalking(msg.content)
|
||||||
// loadLocalJsonAndPlay()
|
// loadLocalJsonAndPlay()
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -434,6 +432,7 @@ class MainActivity : BaseViewModelActivity<ActivityMainBinding, MainViewModel>()
|
|||||||
word: String,
|
word: String,
|
||||||
audioUrl: String
|
audioUrl: String
|
||||||
) {
|
) {
|
||||||
|
LogUtils.eTag("lrs","onAudioProgressUpdated:${state}")
|
||||||
val wakeupUrl = UserInfoManager.userInfo?.wakeUpAudioUrl
|
val wakeupUrl = UserInfoManager.userInfo?.wakeUpAudioUrl
|
||||||
|
|
||||||
if (audioUrl != wakeupUrl) return
|
if (audioUrl != wakeupUrl) return
|
||||||
@ -444,7 +443,7 @@ class MainActivity : BaseViewModelActivity<ActivityMainBinding, MainViewModel>()
|
|||||||
promptPlaying = true
|
promptPlaying = true
|
||||||
voiceController?.onPlayStartPrompt()
|
voiceController?.onPlayStartPrompt()
|
||||||
startPlayTimeoutJob?.cancel()
|
startPlayTimeoutJob?.cancel()
|
||||||
LogUtils.eTag("MainActivity","等待超时")
|
LogUtils.eTag("MainActivity", "等待超时")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -461,9 +460,9 @@ class MainActivity : BaseViewModelActivity<ActivityMainBinding, MainViewModel>()
|
|||||||
id: Int,
|
id: Int,
|
||||||
sortId: Int,
|
sortId: Int,
|
||||||
state: Int,//0stop 2pause 1play 3complete 4loading 5error
|
state: Int,//0stop 2pause 1play 3complete 4loading 5error
|
||||||
text: String,
|
text: String
|
||||||
isFinal: Boolean
|
|
||||||
) {
|
) {
|
||||||
|
LogUtils.eTag("lrs","onStreamAudioProgressUpdated:${state}")
|
||||||
when (state) {
|
when (state) {
|
||||||
1 -> {
|
1 -> {
|
||||||
if (!backPlaying) {
|
if (!backPlaying) {
|
||||||
|
|||||||
@ -131,20 +131,20 @@ class UnityPlayerHolder private constructor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun sendVoiceToUnity(
|
fun sendVoiceToUnity(
|
||||||
type: String = "0",
|
mp3Url: String
|
||||||
voiceInfo: MutableList<VoiceBeanResp> = mutableListOf()
|
|
||||||
) {
|
) {
|
||||||
sendMessageToUnity(
|
sendMessageToUnity(
|
||||||
"unitychan_dynamic",
|
"AudioPlayer",
|
||||||
"StartCoroutineFromAndroid",
|
"StartCoroutineFromAndroid",
|
||||||
GsonUtils.toJson(UnitySendBean(type, voiceInfo))
|
mp3Url
|
||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun startTalking(pcmStr: String) {
|
fun startTalking(pcmStr: String) {
|
||||||
sendMessageToUnity(
|
sendMessageToUnity(
|
||||||
"unitychan_dynamic",
|
"AudioPlayer",
|
||||||
"StartStreamFromAndroid",
|
"StartStreamFromAndroid",
|
||||||
pcmStr
|
pcmStr
|
||||||
)
|
)
|
||||||
|
|||||||
@ -31,12 +31,5 @@
|
|||||||
app:layout_constraintTop_toTopOf="parent"/>
|
app:layout_constraintTop_toTopOf="parent"/>
|
||||||
|
|
||||||
|
|
||||||
<com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer
|
|
||||||
android:id="@+id/standardGSYVideoPlayer"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"/>
|
|
||||||
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
Loading…
x
Reference in New Issue
Block a user