语音转文字

This commit is contained in:
18401019693 2022-10-25 14:05:33 +08:00
parent b4e048bf74
commit 172b37ece2
11 changed files with 94 additions and 54 deletions

View File

@ -41,7 +41,7 @@ public class ProcessFragment extends Fragment {
* @param permissions * @param permissions
* @return true 有权限 false无权限 * @return true 有权限 false无权限
*/ */
private boolean checkPermissions(String[] permissions) { public boolean checkPermissions(String[] permissions) {
for (String permission : permissions) { for (String permission : permissions) {
if (ContextCompat.checkSelfPermission(mContext, permission) != PackageManager.PERMISSION_GRANTED) { if (ContextCompat.checkSelfPermission(mContext, permission) != PackageManager.PERMISSION_GRANTED) {
return false; return false;

View File

@ -1,6 +1,7 @@
package com.yunbao.common.utils; package com.yunbao.common.utils;
import android.content.Intent; import android.content.Intent;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
@ -28,14 +29,17 @@ public class ProcessResultUtil {
mFragment.requestPermissions(permissions, runnable); mFragment.requestPermissions(permissions, runnable);
} }
public boolean checkPermissions(String[] permissions) {
return mFragment.checkPermissions(permissions);
}
public void startActivityForResult(Intent intent, ActivityResultCallback callback){ public void startActivityForResult(Intent intent, ActivityResultCallback callback) {
mFragment.startActivityForResult(intent,callback); mFragment.startActivityForResult(intent, callback);
} }
public void release(){ public void release() {
if(mFragment!=null){ if (mFragment != null) {
mFragment.release(); mFragment.release();
} }
} }

View File

@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
package="com.yunbao.live"> package="com.yunbao.live">
<!--com.kugou.fanxing.allinone.watch.liveroominone.media.FALiveRoomInOneActivity"--> <!--com.kugou.fanxing.allinone.watch.liveroominone.media.FALiveRoomInOneActivity"-->
<uses-permission android:name="android.permission.VIBRATE" />
<application <application
android:allowBackup="true" android:allowBackup="true"

View File

@ -914,8 +914,11 @@ public class LiveAudienceActivity extends LiveActivity {
if (IMLoginManager.get(mContext).isSlide()) { if (IMLoginManager.get(mContext).isSlide()) {
if (event.isVoicePress()) { if (event.isVoicePress()) {
verticalViewPager.setEnableScroll(false); verticalViewPager.setEnableScroll(false);
manager.setSecondPageEnableScroll(false);
} else { } else {
verticalViewPager.setEnableScroll(true); verticalViewPager.setEnableScroll(true);
manager.setSecondPageEnableScroll(true);
} }
} }

View File

@ -83,8 +83,8 @@ public class VoiceDialog extends AbsDialogFragment {
protected void setWindowAttributes(Window window) { protected void setWindowAttributes(Window window) {
window.setWindowAnimations(com.yunbao.common.R.style.bottomToTopAnim); window.setWindowAnimations(com.yunbao.common.R.style.bottomToTopAnim);
WindowManager.LayoutParams params = window.getAttributes(); WindowManager.LayoutParams params = window.getAttributes();
params.width = DpUtil.dp2px(350); params.width =WindowManager.LayoutParams.WRAP_CONTENT;
params.height = DpUtil.dp2px(200); params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.gravity = Gravity.CENTER; params.gravity = Gravity.CENTER;
window.setAttributes(params); window.setAttributes(params);
} }
@ -99,6 +99,8 @@ public class VoiceDialog extends AbsDialogFragment {
gifView = (GifImageView) findViewById(R.id.gif_view); gifView = (GifImageView) findViewById(R.id.gif_view);
startRecognize(); startRecognize();
iconWithdraw.setVisibility(View.GONE); iconWithdraw.setVisibility(View.GONE);
gifView.setVisibility(View.GONE);
voiceFluctuations.setVisibility(View.VISIBLE);
} }
/** /**
@ -116,10 +118,13 @@ public class VoiceDialog extends AbsDialogFragment {
* 上划取消 * 上划取消
*/ */
public void notWithdraw() { public void notWithdraw() {
voiceFluctuations.setVisibility(View.VISIBLE); if (TextUtils.isEmpty(sendMessage())){
voiceFluctuations.setVisibility(View.VISIBLE);
}else {
gifView.setVisibility(View.VISIBLE);
}
iconWithdraw.setVisibility(View.GONE); iconWithdraw.setVisibility(View.GONE);
fingersSlide.setText(getString(R.string.fingers_slide)); fingersSlide.setText(getString(R.string.fingers_slide));
gifView.setVisibility(View.VISIBLE);
isSend = true; isSend = true;
} }
@ -129,7 +134,7 @@ public class VoiceDialog extends AbsDialogFragment {
RecognizerListener recognizerListener = new RecognizerListener() { RecognizerListener recognizerListener = new RecognizerListener() {
@Override @Override
public void onVolumeChanged(int volume, byte[] bytes) { public void onVolumeChanged(int volume, byte[] bytes) {
if (volume > 20) { if (volume > 10) {
gifView.setVisibility(View.VISIBLE); gifView.setVisibility(View.VISIBLE);
voiceFluctuations.setVisibility(View.GONE); voiceFluctuations.setVisibility(View.GONE);
} }
@ -138,14 +143,12 @@ public class VoiceDialog extends AbsDialogFragment {
@Override @Override
public void onBeginOfSpeech() { public void onBeginOfSpeech() {
Log.e(TAG, "onBeginOfSpeech 开始讲话"); Log.e(TAG, "onBeginOfSpeech 开始讲话");
voiceFluctuations.setVisibility(View.GONE);
gifView.setVisibility(View.VISIBLE);
} }
@Override @Override
public void onEndOfSpeech() { public void onEndOfSpeech() {
Log.e(TAG, "onBeginOfSpeech 结束讲话"); Log.e(TAG, "onBeginOfSpeech 结束讲话");
ImgLoader.displayGif(mContext, R.mipmap.img_p, voiceFluctuations);
if (TextUtils.isEmpty(voiceChat.getText())) { if (TextUtils.isEmpty(voiceChat.getText())) {
dismiss(); dismiss();
TextHintDialog textHintDialog = new TextHintDialog(); TextHintDialog textHintDialog = new TextHintDialog();

View File

@ -1,5 +1,6 @@
package com.yunbao.live.views; package com.yunbao.live.views;
import android.Manifest;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
@ -8,6 +9,7 @@ import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Vibrator;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
@ -22,6 +24,8 @@ import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.ViewFlipper; import android.widget.ViewFlipper;
import androidx.fragment.app.FragmentActivity;
import com.opensource.svgaplayer.SVGADrawable; import com.opensource.svgaplayer.SVGADrawable;
import com.opensource.svgaplayer.SVGAImageView; import com.opensource.svgaplayer.SVGAImageView;
import com.opensource.svgaplayer.SVGAParser; import com.opensource.svgaplayer.SVGAParser;
@ -36,6 +40,7 @@ import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.http.HttpClient; import com.yunbao.common.http.HttpClient;
import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.Bus;
import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.DpUtil;
import com.yunbao.common.utils.ProcessResultUtil;
import com.yunbao.common.utils.SVGAViewUtils; import com.yunbao.common.utils.SVGAViewUtils;
import com.yunbao.common.utils.SpUtil; import com.yunbao.common.utils.SpUtil;
import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.ToastUtil;
@ -129,6 +134,7 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder {
SVGADrawable drawable = new SVGADrawable(videoItem); SVGADrawable drawable = new SVGADrawable(videoItem);
svga_new_user_gif.setImageDrawable(drawable); svga_new_user_gif.setImageDrawable(drawable);
SVGAViewUtils.playEndClear(svga_new_user_gif); SVGAViewUtils.playEndClear(svga_new_user_gif);
} }
@Override @Override
@ -269,15 +275,27 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder {
voiceButton.setOnTouchListener((v, event) -> { voiceButton.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_DOWN) { if (event.getAction() == MotionEvent.ACTION_DOWN) {
downY = event.getY(); downY = event.getY();
//按下 if (mProcessResultUtil.checkPermissions(new String[]{Manifest.permission.RECORD_AUDIO})) {
handler.postDelayed(mLongPressed, 500); //按下
handler.postDelayed(mLongPressed, 500);
} else {
mProcessResultUtil.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, new Runnable() {
@Override
public void run() {
}
});
}
} else if (event.getAction() == MotionEvent.ACTION_MOVE) { } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
float moveY = event.getY(); float moveY = event.getY();
if (downY - moveY > 120) { if (downY - moveY > 120) {
voiceDialog.withdraw(); if (voiceDialog != null)
voiceDialog.withdraw();
} }
if ((downY - moveY < 100) && (downY - moveY > 30)) { if ((downY - moveY < 100) && (downY - moveY > 30)) {
voiceDialog.notWithdraw(); if (voiceDialog != null)
voiceDialog.notWithdraw();
} }
} else if (event.getAction() == MotionEvent.ACTION_UP) { } else if (event.getAction() == MotionEvent.ACTION_UP) {
//松开 //松开
@ -297,15 +315,18 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder {
} }
return true; return true;
}); });
mProcessResultUtil = new ProcessResultUtil((FragmentActivity) mContext);
} }
private float downY = 0; private float downY = 0;
private ProcessResultUtil mProcessResultUtil;
private VoiceDialog voiceDialog = null; private VoiceDialog voiceDialog = null;
private Runnable mLongPressed = new Runnable() { private Runnable mLongPressed = new Runnable() {
@Override @Override
public void run() { public void run() {
Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(30);//震动时间(ms)
if (voiceDialog == null) { if (voiceDialog == null) {
voiceDialog = new VoiceDialog(); voiceDialog = new VoiceDialog();
} }

View File

@ -14,6 +14,7 @@ import android.os.Handler;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.FrameLayout; import android.widget.FrameLayout;
@ -61,7 +62,6 @@ import com.yunbao.common.utils.WordUtil;
import com.yunbao.common.utils.formatBigNum; import com.yunbao.common.utils.formatBigNum;
import com.yunbao.common.views.weight.LiveFloatView; import com.yunbao.common.views.weight.LiveFloatView;
import com.yunbao.live.R; import com.yunbao.live.R;
import com.yunbao.live.activity.FALiveRoomInOneActivity;
import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveActivity;
import com.yunbao.live.activity.LiveAudienceActivity; import com.yunbao.live.activity.LiveAudienceActivity;
import com.yunbao.live.bean.LiveBuyGuardMsgBean; import com.yunbao.live.bean.LiveBuyGuardMsgBean;
@ -408,7 +408,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
@Override @Override
public void onStop() { public void onStop() {
boolean isForeground = LifecycleUtils.INSTANCE.isForeground(); boolean isForeground = LifecycleUtils.INSTANCE.isForeground();
if (mLiveBean != null && !isQuitF && !isForeground) { boolean floatPermission = PermissionUtils.checkPermission(mContext);
if (mLiveBean != null && !isQuitF && !isForeground && floatPermission) {
LiveFloatView.getInstance() LiveFloatView.getInstance()
.cacheLiveData(mLiveBean, mLiveType, mLiveSDK, mLiveTypeVal) .cacheLiveData(mLiveBean, mLiveType, mLiveSDK, mLiveTypeVal)
.builderSystemFloat(mContext, mLiveBean.getPull()); .builderSystemFloat(mContext, mLiveBean.getPull());
@ -1626,4 +1627,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
mLiveRoomViewHolder.chatScrollToBottom(); mLiveRoomViewHolder.chatScrollToBottom();
} }
} }
public void setSecondPageEnableScroll(boolean enableScroll) {
mViewPager.setCanScroll(enableScroll);
}
} }

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="9dp"/> <corners android:radius="9dp"/>
<solid android:color="#000000"/> <solid android:color="#90000000"/>
</shape> </shape>

View File

@ -11,8 +11,8 @@
<ImageView <ImageView
android:id="@+id/voice_press" android:id="@+id/voice_press"
android:layout_width="54dp" android:layout_width="64dp"
android:layout_height="54dp" android:layout_height="64dp"
android:visibility="gone" android:visibility="gone"
android:src="@mipmap/icon_voice_press" android:src="@mipmap/icon_voice_press"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"

View File

@ -1,23 +1,27 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="270dp" android:layout_width="wrap_content"
android:layout_height="170dp" android:layout_height="wrap_content"
android:background="@drawable/bg_voice_chat"> android:background="@drawable/bg_voice_chat"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView <ImageView
android:id="@+id/icon_withdraw" android:id="@+id/icon_withdraw"
android:layout_width="38dp" android:layout_width="38dp"
android:layout_height="31dp" android:layout_height="31dp"
android:layout_centerHorizontal="true" android:layout_marginTop="23dp"
android:layout_marginTop="5dp" android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:src="@mipmap/icon_withdraw" /> android:src="@mipmap/icon_withdraw" />
<ImageView <ImageView
android:id="@+id/voice_fluctuations" android:id="@+id/voice_fluctuations"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:layout_marginTop="23dp"
android:layout_marginTop="30dp" android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:src="@mipmap/img_p" /> android:src="@mipmap/img_p" />
@ -25,31 +29,31 @@
android:id="@+id/gif_view" android:id="@+id/gif_view"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:layout_marginTop="23dp"
android:layout_marginTop="30dp" android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:background="@mipmap/voice_fluctuations" android:background="@mipmap/voice_fluctuations"
android:visibility="gone" /> android:visibility="gone" />
<TextView
android:id="@+id/fingers_slide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="16dp"
android:text="@string/fingers_slide"
android:textColor="#9A9A9A" />
<TextView <TextView
android:id="@+id/voice_chat" android:id="@+id/voice_chat"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:layout_marginStart="5dp"
android:layout_marginStart="8dp" android:layout_marginTop="8dp"
android:layout_marginTop="55dp" android:layout_marginBottom="10dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="5dp"
android:layout_marginBottom="8dp" android:maxLines="5"
android:maxLines="4"
android:textColor="#FFFFFF" android:textColor="#FFFFFF"
android:textSize="14sp" /> android:textSize="14sp" />
</RelativeLayout>
<TextView
android:id="@+id/fingers_slide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="@string/fingers_slide"
android:textColor="#9A9A9A" />
</LinearLayout>

View File

@ -93,7 +93,7 @@
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="99dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1"> android:layout_weight="1">
@ -138,8 +138,7 @@
android:id="@+id/btn_start" android:id="@+id/btn_start"
android:layout_width="60dp" android:layout_width="60dp"
android:layout_height="60dp" android:layout_height="60dp"
android:layout_centerHorizontal="true" android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:onClick="mainClick" android:onClick="mainClick"
android:src="@mipmap/icon_main_start" /> android:src="@mipmap/icon_main_start" />
</RelativeLayout> </RelativeLayout>