Skip to content

Commit

Permalink
👷 新增翻译readme.yml
Browse files Browse the repository at this point in the history
🎨 移除RecordVoiceView.kt相关
✅ 优化demo
  • Loading branch information
SheTieJun committed May 9, 2024
1 parent 4027c4b commit fcdc2b4
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 441 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/readme.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Translate README

on:
# 这个选项可以使你手动在 Action tab 页面触发工作流
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 12.x
# ISO Langusge Codes: https://cloud.google.com/translate/docs/languages
- name: Adding README - English
uses: dephraiim/translate-readme@main
with:
LANG: en
30 changes: 24 additions & 6 deletions README.MD → README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# 录音工具-Mp3Recorder
<h1 align="center">
录音工具-Mp3Recorder
</h1>

[![](https://jitpack.io/v/SheTieJun/Mp3Recorder.svg)](https://jitpack.io/#SheTieJun/Mp3Recorder) ![buildWorkflow](https://github.com/SheTieJun/Mp3Recorder/actions/workflows/android.yml/badge.svg)

<p align="center">
<a href="README.en.md">English</a> | <a href="README.md">简体中文</a>
</p>

- 边录边转码MP3,默认启动系统自带[如果手机支持]的AEC、NC、AGC。
- 支持暂停,实时返回已**录制时长**和当前**声音大小**,已录制的那段音频是**可以播放**的.
Expand All @@ -13,6 +19,7 @@
![](doc/img/recorder.gif)

## 一、接入配置

**[接入配置文档](https://github.com/SheTieJun/Mp3Recorder/wiki/%E6%8E%A5%E5%85%A5%E6%96%87%E6%A1%A3)**

### 1. 如何选择
Expand Down Expand Up @@ -83,13 +90,15 @@ fun setPitchSemiTones(@FloatRange(from = -12.0, to = 12.0) pitch: Float)

- **[使用说明文档](https://github.com/SheTieJun/Mp3Recorder/wiki/%E4%BD%BF%E7%94%A8%E6%96%87%E6%A1%A3)**
- [音频基础知识](https://blog.csdn.net/StjunF/article/details/121296111)

```
采样频率越高, 声音越接近原始数据。
采样位数越高,声音越接近原始数据。
比特率越高,传送的数据越大,音质越好
```

## 获取手机当前最佳采样率

```kotlin
val am = getSystemService(Context.AUDIO_SERVICE) as AudioManager
val sampleRateStr: String? = am.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE)
Expand Down Expand Up @@ -124,15 +133,19 @@ abstract class BaseRecorder {
* @param outputFile 设置输出路径
* @param isContinue 表示是否拼接在文件末尾,实现继续录制的一种方式
*/
open fun setOutputFile(outputFile: File, isContinue: Boolean = false): BaseRecorder{/*...*/}
open fun setOutputFile(outputFile: File, isContinue: Boolean = false): BaseRecorder {/*...*/
}

//设置录音监听
open fun setRecordListener(recordListener: RecordListener?): BaseRecorder{/*...*/}
open fun setRecordListener(recordListener: RecordListener?): BaseRecorder {/*...*/
}

//设置权限监听
open fun setPermissionListener(permissionListener: PermissionListener?): BaseRecorder{/*...*/}
open fun setPermissionListener(permissionListener: PermissionListener?): BaseRecorder {/*...*/
}

open fun setPCMListener(pcmListener: PCMListener?):BaseRecorder{/*...*/}
open fun setPCMListener(pcmListener: PCMListener?): BaseRecorder {/*...*/
}

//设计背景音乐的url,本地的(网络的可能造成卡死)
abstract fun setBackgroundMusic(url: String): BaseRecorder
Expand Down Expand Up @@ -163,7 +176,8 @@ abstract class BaseRecorder {
abstract fun setAudioSource(@Source audioSource: Int = MediaRecorder.AudioSource.MIC): Boolean

//设置声波过滤器
open fun setFilter(lowpassFreq: Int = 3000, highpassFreq: Int = 200) {/*...*/}
open fun setFilter(lowpassFreq: Int = 3000, highpassFreq: Int = 200) {/*...*/
}

//初始最大录制时间 和提醒时间 remind = maxTime - remindDiffTime
abstract fun setMaxTime(maxTime: Int, remindDiffTime: Int? = null): BaseRecorder
Expand Down Expand Up @@ -216,8 +230,12 @@ abstract class BaseRecorder {
```

## 其他

### 1. [Old version](https://github.com/SheTieJun/Mp3Recorder/tree/master_copy)

### 2. [Update_log](https://github.com/SheTieJun/Mp3Recorder/wiki/%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97)

### 3. [License](https://github.com/SheTieJun/Mp3Recorder/blob/master/LICENSE)

### 4. [MediaRecorder介绍](doc/MediaRecorder.MD):部分场景下使用MediaRecorder更加方便。

12 changes: 8 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<manifest xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
android:maxSdkVersion="32"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" /> <!-- 修复权限 -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<!-- To handle the reselection within the app on devices running Android 14
or higher if your app targets Android 14 (API level 34) or higher. -->
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />

<application
android:allowBackup="true"
Expand All @@ -38,7 +43,6 @@
android:name=".record.activity.mix.RecordActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:exported="false"
android:screenOrientation="portrait"
android:theme="@style/AppTheme"
android:windowSoftInputMode="stateHidden|adjustPan" />
</application>
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/me/shetj/mp3recorder/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package me.shetj.mp3recorder

import android.animation.ObjectAnimator
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.media.AudioFormat
import android.media.AudioManager
Expand Down Expand Up @@ -60,13 +61,13 @@ class MainActivity : BaseBindingActivity<ActivityMainTestBinding, BaseViewModel>
override fun initBaseView() {
mBinding.btnDemo3.setOnClickListener {
if (FixPermission.checkReadMediaFile(this, isRequest = true)) {
start<RecordActivity>()
startActivity(Intent(this,RecordActivity::class.java))
}
}

mBinding.msg.apply {
append("获取当前手机录音最佳参数:")
append("最佳采样率${getBestSampleRate()}\n")
append("\n最佳采样率${getBestSampleRate()}\n")
append("\n录音最小缓存大小(${getBestSampleRate()},1,${AudioFormat.ENCODING_PCM_16BIT}):${AudioRecord.getMinBufferSize(
getBestSampleRate(),
1, AudioFormat.ENCODING_PCM_16BIT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@

package me.shetj.mp3recorder.record

import android.Manifest
import android.annotation.SuppressLint
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
Expand Down Expand Up @@ -68,6 +71,9 @@ object RecordingNotification {


private fun notify(context: Context, notification: Notification) {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
return
}
NotificationManagerCompat.from(context).notify(RECORD_NOTIFICATION_ID, notification)
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@

package me.shetj.mp3recorder.record.activity.mix

import android.Manifest
import android.os.Bundle
import android.transition.Transition
import android.transition.TransitionInflater
import android.transition.TransitionManager
import android.widget.FrameLayout
import androidx.appcompat.widget.AppCompatButton
import androidx.core.view.isVisible
import me.shetj.base.ktx.hasPermission
import me.shetj.base.fix.FixPermission
import me.shetj.base.mvp.BaseActivity
import me.shetj.base.mvp.EmptyPresenter
import me.shetj.base.tools.app.ArmsUtils.Companion.statuInScreen
import me.shetj.mp3recorder.R
import me.shetj.mp3recorder.record.RecordingNotification
import me.shetj.mp3recorder.record.utils.EventCallback
import kotlinx.coroutines.delay
import me.shetj.base.fix.FixPermission
import me.shetj.base.ktx.launch


/**
Expand All @@ -36,12 +32,14 @@ class RecordActivity : BaseActivity<EmptyPresenter>(), EventCallback {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_my_record)
enabledOnBack = true
}


override fun initBaseView() {
setContentView(R.layout.activity_my_record)
statuInScreen(true)
setOrientation(false)
canRecord()
mFrameLayout = findViewById(R.id.frameLayout)
btnRecorderType = findViewById(R.id.btn_recorderType)
Expand Down Expand Up @@ -100,11 +98,11 @@ class RecordActivity : BaseActivity<EmptyPresenter>(), EventCallback {
FixPermission.checkReadMediaFile(this,true)
}

override fun onBackPressed() {
override fun onBack() {
if (isRecord) {
recordPage!!.onStop()
} else {
super.onBackPressed()
}else{
super.onBack()
}
}

Expand Down
Loading

0 comments on commit fcdc2b4

Please sign in to comment.