Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Projects_2025/team7/PPT.pptx
Binary file not shown.
Binary file added Projects_2025/team7/Poster.pptx
Binary file not shown.
Binary file added Projects_2025/team7/llama.android/.DS_Store
Binary file not shown.
33 changes: 33 additions & 0 deletions Projects_2025/team7/llama.android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Log/OS Files
*.log

# Android Studio generated files and folders
captures/
.externalNativeBuild/
.cxx/
*.apk
output.json

# IntelliJ
*.iml
.idea/
misc.xml
deploymentTargetDropDown.xml
render.experimental.xml

# Keystore files
*.jks
*.keystore

# Google Services (e.g. APIs or Firebase)
google-services.json

# Android Profiling
*.hprof
Empty file.
99 changes: 99 additions & 0 deletions Projects_2025/team7/llama.android/VOSK_SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Vosk 离线语音识别设置指南

本应用已修改为使用 Vosk 进行离线语音识别,不再依赖系统的语音识别服务。

## 准备工作

### 1. 下载 Vosk 模型

您需要下载一个 Vosk 语音识别模型。根据您的需求选择:

#### 中文模型(推荐)
- **小型模型**(约 42 MB):
- 下载地址:https://alphacephei.com/vosk/models/vosk-model-small-cn-0.22.zip
- 适合资源受限的设备

- **大型模型**(约 1.8 GB):
- 下载地址:https://alphacephei.com/vosk/models/vosk-model-cn-0.22.zip
- 识别精度更高

#### 英文模型
- **小型模型**(约 40 MB):
- 下载地址:https://alphacephei.com/vosk/models/vosk-model-small-en-us-0.15.zip

- **大型模型**(约 1.8 GB):
- 下载地址:https://alphacephei.com/vosk/models/vosk-model-en-us-0.22.zip

### 2. 安装模型到项目

1. 下载并解压您选择的模型文件
2. 将解压后的模型文件夹重命名为 `model-cn`(如果使用中文)或 `model-en`(如果使用英文)
3. 将该文件夹复制到项目的 `app/src/main/assets/` 目录下

文件结构应该如下:
```
llama.android/
└── app/
└── src/
└── main/
└── assets/
└── model-cn/ # 或 model-en
├── am/
├── conf/
├── graph/
└── ivector/
```

### 3. 修改代码(如果使用英文模型)

如果您使用的是英文模型,需要在 `MainActivity.kt` 中修改模型名称:

找到 `initVoskModel()` 函数中的这一行:
```kotlin
val modelPath = StorageService.sync(this, "model-cn")
```

改为:
```kotlin
val modelPath = StorageService.sync(this, "model-en")
```

## 使用说明

1. 构建并运行应用
2. 应用启动时会自动加载 Vosk 模型(首次加载可能需要几秒钟)
3. 查看日志确认模型是否加载成功:"Vosk模型加载成功"
4. 长按麦克风按钮开始录音,松开按钮结束录音
5. 录音过程中会实时显示识别的部分结果
6. 录音结束后显示最终识别结果

## 优势

- ✅ 完全离线工作,不需要网络连接
- ✅ 不依赖系统语音识别服务
- ✅ 隐私保护,语音数据不会上传到服务器
- ✅ 支持多种语言(中文、英文等)
- ✅ 实时显示部分识别结果

## 故障排除

### 模型加载失败
- 确认模型文件夹在正确的位置(`app/src/main/assets/model-cn`)
- 确认模型文件夹内包含必要的子文件夹(am, conf, graph, ivector)
- 检查应用日志中的错误信息

### 识别效果不佳
- 尝试使用大型模型以获得更好的识别精度
- 确保录音环境安静
- 对着麦克风清晰地说话

### 应用崩溃
- 检查是否有足够的存储空间
- 确认已授予麦克风权限
- 查看崩溃日志获取详细错误信息

## 更多信息

- Vosk 官方网站:https://alphacephei.com/vosk/
- Vosk Android 文档:https://github.com/alphacep/vosk-android-demo
- 更多语言模型:https://alphacephei.com/vosk/models
1 change: 1 addition & 0 deletions Projects_2025/team7/llama.android/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
70 changes: 70 additions & 0 deletions Projects_2025/team7/llama.android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
}

android {
namespace = "com.example.llama"
compileSdk = 34

defaultConfig {
applicationId = "com.example.llama"
minSdk = 33
targetSdk = 34
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.1"
}
}

dependencies {

implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
implementation("androidx.activity:activity-compose:1.8.2")
implementation(platform("androidx.compose:compose-bom:2023.08.00"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
implementation("androidx.compose.material:material-icons-extended:1.6.0")
implementation(project(":llama"))

// Vosk 离线语音识别
implementation("com.alphacephei:vosk-android:0.3.47")

testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation(platform("androidx.compose:compose-bom:2023.08.00"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
}
21 changes: 21 additions & 0 deletions Projects_2025/team7/llama.android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
52 changes: 52 additions & 0 deletions Projects_2025/team7/llama.android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>

<!--1. AndroidManifest.xml是用于面向安卓手机的系统-->
<!--1.1 告诉安卓系统,此应用需要的权限-->
<!--1.2 以及规定应用图标,应用名-->
<!--1.3 还有此应用程序的入口-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<!--1.1 告诉安卓系统,此应用需要的权限-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<!--1.2 以及规定应用图标,应用名-->
<!--1.2.1 android:allowBackup, dataExtractionRules, fullBackupContent和数据备份有关系,和数据持久化无关,本地数据持久化要专门做-->
<!--1.2.2 android:icon, label, roundIcon就是应用图标,应用名-->
<!--1.2.3 android:supportsRtl就是支持从右到左的语言-->
<!--1.2.3 android:theme就是主题颜色搭配,Theme.LlamaAndroid是values/themes.xml中的一个style类型tag,这个tag里会有一系列item规定各种细节的颜色,这一整套搭配叫做一个主题-->
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"

android:icon="@mipmap/ic_launcher2"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"
android:theme="@style/Theme.LlamaAndroid"
>

<!--1.3 还有此应用程序的入口-->
<!--1.3.1 指定应用程序入口对应的类是MainActivity类-->
<!--1.3.2 表示此应用可以被手机上的安卓系统启动-->
<!--1.3.3 选一下主题-->
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.LlamaAndroid">
<!--1.4 intent-filter用于规定这个Activity可以响应哪些intent-->
<!--1.4.1 action用MAIN的话表示此活动作为应用入口,一个应用只有一个应用入口-->
<!--1.4.2 category不知道,但是LAUNCHER的作用是让这个应用可以出现在安卓系统的桌面上-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
30 changes: 30 additions & 0 deletions Projects_2025/team7/llama.android/app/src/main/assets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Vosk 模型目录

请将下载的 Vosk 模型文件夹放在此目录下。

## 下载模型

### 中文模型(推荐)
小型模型(42 MB):https://alphacephei.com/vosk/models/vosk-model-small-cn-0.22.zip

### 英文模型
小型模型(40 MB):https://alphacephei.com/vosk/models/vosk-model-small-en-us-0.15.zip

## 安装步骤

1. 下载上述模型之一
2. 解压缩下载的文件
3. 将解压后的文件夹重命名为 `model-cn`(中文)或 `model-en`(英文)
4. 将该文件夹复制到此目录(assets)下

最终目录结构应该是:
```
assets/
└── model-cn/ # 或 model-en
├── am/
├── conf/
├── graph/
└── ivector/
```

更多详细信息,请参考项目根目录下的 VOSK_SETUP.md 文件。
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
US English model for mobile Vosk applications

Copyright 2020 Alpha Cephei Inc

Accuracy: 10.38 (tedlium test) 9.85 (librispeech test-clean)
Speed: 0.11xRT (desktop)
Latency: 0.15s (right context)


Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
--sample-frequency=16000
--use-energy=false
--num-mel-bins=40
--num-ceps=40
--low-freq=20
--high-freq=7600
--allow-downsample=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--min-active=200
--max-active=3000
--beam=10.0
--lattice-beam=2.0
--acoustic-scale=1.0
--frame-subsampling-factor=3
--endpoint.silence-phones=1:2:3:4:5:6:7:8:9:10
--endpoint.rule2.min-trailing-silence=0.5
--endpoint.rule3.min-trailing-silence=0.75
--endpoint.rule4.min-trailing-silence=1.0
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
Loading