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