保存时间:2026/3/29 16:32:16
# 查看所有端口的监听状态
sudo netstat -tuln
# 查看特定端口,比如8080
sudo netstat -tuln | grep 8080
# 或者用更现代的ss命令,同样查看8080端口
sudo ss -tuln | grep 8080
# 查看UFW防火墙状态
sudo ufw status
# 如果状态是inactive,说明防火墙没开
# 开启防火墙
sudo ufw enable
# 关闭防火墙
sudo ufw disable
# 查看所有网络接口的IP地址等信息
ip addr show
# 查看路由表,看数据包会从哪个网卡发出去
ip route show
# 查看DNS配置
cat /etc/resolv.conf
# 测试到某个IP或域名的连通性
ping www.baidu.com
# 测试到某个IP和端口的连通性
telnet 192.168.1.1 80
# 或者用nc命令
nc -zv 192.168.1.1 80
/etc/resolv.conf 确实是一个由系统服务动态生成的软链接,不建议直接修改。网络设置IPv4 或 IPv6 标签页DNS 自动获取改为 手动,然后输入你想要的 DNS 地址(如 8.8.8.8)/etc/netplan/ 目录下nameservers 部分指定 DNS 服务器地址sudo netplan apply 使配置生效/etc/resolv.conf 文件会被系统覆盖,所以上面两种方法才是正确的姿势。systemd-resolve 这个命令来测试。systemd-resolve --status | grep "DNS Servers" -A2
tun0 或类似的)对应的 DNS 服务器是不是 VPN 服务商提供的地址,而不是你本地网络的。dig 命令来做一个更直接的测试,看看解析某个特定域名时具体用了哪个服务器:dig @8.8.8.8 www.google.com
8.8.8.8 换成你 VPN 的 DNS 服务器地址,就能验证这个 DNS 服务器能否正确解析域名了。AutoGPT、MetaGPT 或者 LangChain,都提供了将大语言模型本地化部署的能力。你可以利用这些框架,搭建一个能理解你的指令、并在本地执行命令的 Agent。ai "帮我查看端口8080的占用情况",它就能直接返回结果,甚至帮你执行。whisper 这样的工具转成文字),然后调用我的 API 获取命令,最后在本地执行。import subprocess
import sys
def run_command(command):
"""执行命令并返回结果"""
try:
# 执行命令,捕获输出和错误
result = subprocess.run(
command,
shell=True,
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
return result.stdout
except subprocess.CalledProcessError as e:
return f"命令执行失败: {e.stderr}"
def main():
if len(sys.argv) < 2:
print("请提供指令参数。")
print("用法: python local_agent.py \"你的指令,例如:查看端口8080的占用情况\"")
sys.exit(1)
# 获取用户输入的指令
user_input = ' '.join(sys.argv[1:])
print(f"收到指令: {user_input}")
# 这里只是一个简单的例子,实际应用中需要更复杂的指令解析
# 这里直接将用户输入当作命令执行(注意安全风险!)
print("正在执行命令...")
output = run_command(user_input)
print("命令输出:")
print(output)
if __name__ == "__main__":
main()
local_agent.pypython local_agent.py "ls -l"ls -l 命令并显示结果sudo lsof -i :8080。import subprocess
import sys
import requests
import json
# --- 请在这里填写你的配置 ---
API_KEY = "sk-你的豆包API密钥"
API_URL = "https://api.doubao.com/v1/chat/completions" # 假设的API地址,请根据实际情况修改
# --- 配置结束 ---
def get_command_from_ai(user_question):
"""调用AI API获取对应的命令"""
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
payload = {
"model": "doubao-pro", # 假设的模型名称
"messages": [
{"role": "system", "content": "你是一个精通Linux命令的AI助手。用户会问一个问题,你只需要返回能解决问题的那个Shell命令,不要加任何多余的解释。"},
{"role": "user", "content": user_question}
],
"temperature": 0.0
}
try:
response = requests.post(API_URL, headers=headers, json=payload)
response.raise_for_status() # 检查请求是否成功
result = response.json()
return result['choices'][0]['message']['content'].strip()
except Exception as e:
return f"获取命令失败: {str(e)}"
def run_command(command):
"""执行命令并返回结果"""
print(f"即将执行命令: {command}")
try:
result = subprocess.run(
command,
shell=True,
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
return "命令执行成功:\n" + result.stdout
except subprocess.CalledProcessError as e:
return f"命令执行失败:\n{e.stderr}"
def main():
if len(sys.argv) < 2:
print("请提供你的问题作为参数。")
print("用法: python ai_shell.py \"你的问题,例如:查看端口8080的占用情况\"")
sys.exit(1)
user_question = ' '.join(sys.argv[1:])
print(f"你问的是: {user_question}")
# 1. 从AI获取命令
print("正在思考解决方案...")
command = get_command_from_ai(user_question)
if command.startswith("获取命令失败"):
print(command)
sys.exit(1)
# 2. 执行命令
print("正在执行...")
output = run_command(command)
# 3. 显示结果
print("\n" + "="*50)
print(output)
if __name__ == "__main__":
main()
API_KEY 变量里。API_URL 和 model 参数是否正确,可能需要根据实际的API文档进行调整。ai_shell.py。python ai_shell.py "帮我查看端口8080被哪个程序占用了"import subprocess
import sys
import requests
import json
# --- 请在这里填写你的配置 ---
API_KEY = "sk-你的豆包API密钥"
API_URL = "https://api.doubao.com/v1/chat/completions" # 假设的API地址,请根据实际情况修改
# --- 配置结束 ---
def get_command_from_ai(user_question):
"""调用AI API获取对应的命令"""
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
payload = {
"model": "doubao-pro", # 假设的模型名称
"messages": [
{"role": "system", "content": "你是一个精通Linux命令的AI助手。用户会问一个问题,你只需要返回能解决问题的那个Shell命令,不要加任何多余的解释。"},
{"role": "user", "content": user_question}
],
"temperature": 0.0
}
try:
response = requests.post(API_URL, headers=headers, json=payload)
response.raise_for_status() # 检查请求是否成功
result = response.json()
return result['choices'][0]['message']['content'].strip()
except Exception as e:
return f"获取命令失败: {str(e)}"
def run_command(command):
"""执行命令并返回结果"""
print(f"执行命令: {command}")
try:
result = subprocess.run(
command,
shell=True,
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
return "命令执行成功:\n" + result.stdout
except subprocess.CalledProcessError as e:
return f"命令执行失败:\n{e.stderr}"
def main():
if len(sys.argv) < 2:
print("请提供你的问题作为参数。")
print("用法: python ai_shell.py \"你的问题,例如:查看端口8080的占用情况\"")
sys.exit(1)
user_question = ' '.join(sys.argv[1:])
print(f"你问的是: {user_question}")
# 1. 从AI获取命令
print("正在思考解决方案...")
command = get_command_from_ai(user_question)
if command.startswith("获取命令失败"):
print(command)
sys.exit(1)
# 2. 显示命令并请求确认
print("\n我建议执行以下命令:")
print(f"\033[93m{command}\033[0m") # 黄色显示
print("\n这个命令可能会修改你的系统设置或文件。")
print("请仔细检查命令内容!")
confirm = input("\n是否执行此命令? (y/N): ").strip().lower()
if confirm != 'y':
print("命令已取消。")
sys.exit(0)
# 3. 执行命令
print("\n正在执行...")
output = run_command(command)
# 4. 显示结果
print("\n" + "="*50)
print(output)
if __name__ == "__main__":
main()
ai_shell.log 文件里,方便你随时回顾。import subprocess
import sys
import requests
import json
from datetime import datetime
# --- 请在这里填写你的配置 ---
API_KEY = "sk-你的豆包API密钥"
API_URL = "https://api.doubao.com/v1/chat/completions" # 假设的API地址,请根据实际情况修改
LOG_FILE = "ai_shell.log"
# --- 配置结束 ---
def log_message(message, is_command=False, is_result=False):
"""记录日志信息到文件"""
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# 日志前缀
if is_command:
log_prefix = "[COMMAND]"
elif is_result:
log_prefix = "[RESULT]"
else:
log_prefix = "[INFO]"
log_entry = f"{timestamp} {log_prefix} {message}\n"
# 写入日志文件
with open(LOG_FILE, "a", encoding="utf-8") as f:
f.write(log_entry)
# 同时在控制台显示
print(log_entry.strip())
def get_command_from_ai(user_question):
"""调用AI API获取对应的命令"""
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
payload = {
"model": "doubao-pro", # 假设的模型名称
"messages": [
{"role": "system", "content": "你是一个精通Linux命令的AI助手。用户会问一个问题,你只需要返回能解决问题的那个Shell命令,不要加任何多余的解释。"},
{"role": "user", "content": user_question}
],
"temperature": 0.0
}
try:
response = requests.post(API_URL, headers=headers, json=payload)
response.raise_for_status() # 检查请求是否成功
result = response.json()
command = result['choices'][0]['message']['content'].strip()
log_message(f"AI返回的命令: {command}")
return command
except Exception as e:
error_msg = f"获取命令失败: {str(e)}"
log_message(error_msg)
return error_msg
def run_command(command):
"""执行命令并返回结果"""
log_message(f"执行命令: {command}", is_command=True)
try:
result = subprocess.run(
command,
shell=True,
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
output = "命令执行成功:\n" + result.stdout
log_message(output, is_result=True)
return output
except subprocess.CalledProcessError as e:
error_output = f"命令执行失败:\n{e.stderr}"
log_message(error_output, is_result=True)
return error_output
def main():
if len(sys.argv) < 2:
print("请提供你的问题作为参数。")
print("用法: python ai_shell.py \"你的问题,例如:查看端口8080的占用情况\"")
sys.exit(1)
user_question = ' '.join(sys.argv[1:])
log_message(f"用户问题: {user_question}")
# 1. 从AI获取命令
log_message("正在思考解决方案...")
command = get_command_from_ai(user_question)
if command.startswith("获取命令失败"):
print(command)
sys.exit(1)
# 2. 显示命令并请求确认
print("\n我建议执行以下命令:")
print(f"\033[93m{command}\033[0m") # 黄色显示
print("\n这个命令可能会修改你的系统设置或文件。")
print("请仔细检查命令内容!")
confirm = input("\n是否执行此命令? (y/N): ").strip().lower()
if confirm != 'y':
log_message("用户取消了命令执行")
print("命令已取消。")
sys.exit(0)
# 3. 执行命令
log_message("正在执行...")
output = run_command(command)
# 4. 显示结果
print("\n" + "="*50)
print(output)
if __name__ == "__main__":
main()
[INFO]、[COMMAND]、[RESULT] 区分不同类型的日志,更易读。ai_shell.log 文件中,不会丢失。python ai_shell.py 这么长一串,直接在终端里输入 ai "你的问题" 就能用了,更方便。ls, ps, netstat, ss, ping, dig, cat (查看文件), grep 等只读命令。sudo, rm, mv, cp (写入), chmod, chown, apt-get install, echo > file 等任何可能修改系统的命令。get_command_from_ai 函数里,作为给我的系统提示。这样每次调用API时,都会强制提醒我遵守这个规则。你是一个只读的AI助手。你的任务是帮我生成查询系统信息的命令。你只能使用那些不会修改、删除或创建任何文件的命令。你绝不能使用需要sudo权限的命令,也不能使用任何可能改变系统状态的命令。
rm -rf / 这种毁灭性命令。我也不会生成 echo "test" > file.txt 这种写入操作。df -h 查看磁盘分区和使用情况du -sh /home 查看某个目录的大小get_command_from_ai 函数的 payload 部分。我会把这个原则写进 messages 数组里,作为给AI的第一个指令。payload = {
"model": "doubao-pro",
"messages": [
{"role": "system", "content": "你是一个只读的AI助手。你的任务是帮我生成查询系统信息的命令。你只能使用那些不会修改、删除或创建任何文件的命令。你绝不能使用需要sudo权限的命令,也不能使用任何可能改变系统状态的命令。"},
{"role": "user", "content": user_question}
],
"temperature": 0.0
}
import subprocess
import sys
import requests
import json
from datetime import datetime
# --- 请在这里填写你的配置 ---
API_KEY = "sk-你的豆包API密钥"
API_URL = "https://api.doubao.com/v1/chat/completions" # 假设的API地址,请根据实际情况修改
LOG_FILE = "ai_shell.log"
# --- 配置结束 ---
def log_message(message, is_command=False, is_result=False):
"""记录日志信息到文件"""
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# 日志前缀
if is_command:
log_prefix = "[COMMAND]"
elif is_result:
log_prefix = "[RESULT]"
else:
log_prefix = "[INFO]"
log_entry = f"{timestamp} {log_prefix} {message}\n"
# 写入日志文件
with open(LOG_FILE, "a", encoding="utf-8") as f:
f.write(log_entry)
# 同时在控制台显示
print(log_entry.strip())
def get_command_from_ai(user_question):
"""调用AI API获取对应的命令"""
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
payload = {
"model": "doubao-pro", # 假设的模型名称
"messages": [
{"role": "system", "content": "你是一个只读的AI助手。你的任务是帮我生成查询系统信息的命令。你只能使用那些不会修改、删除或创建任何文件的命令。你绝不能使用需要sudo权限的命令,也不能使用任何可能改变系统状态的命令。"},
{"role": "user", "content": user_question}
],
"temperature": 0.0
}
try:
response = requests.post(API_URL, headers=headers, json=payload)
response.raise_for_status() # 检查请求是否成功
result = response.json()
command = result['choices'][0]['message']['content'].strip()
log_message(f"AI返回的命令: {command}")
return command
except Exception as e:
error_msg = f"获取命令失败: {str(e)}"
log_message(error_msg)
return error_msg
def run_command(command):
"""执行命令并返回结果"""
log_message(f"执行命令: {command}", is_command=True)
try:
result = subprocess.run(
command,
shell=True,
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
output = "命令执行成功:\n" + result.stdout
log_message(output, is_result=True)
return output
except subprocess.CalledProcessError as e:
error_output = f"命令执行失败:\n{e.stderr}"
log_message(error_output, is_result=True)
return error_output
def main():
if len(sys.argv) < 2:
print("请提供你的问题作为参数。")
print("用法: python ai_shell.py \"你的问题,例如:查看端口8080的占用情况\"")
sys.exit(1)
user_question = ' '.join(sys.argv[1:])
log_message(f"用户问题: {user_question}")
# 1. 从AI获取命令
log_message("正在思考解决方案...")
command = get_command_from_ai(user_question)
if command.startswith("获取命令失败"):
print(command)
sys.exit(1)
# 2. 显示命令并请求确认
print("\n我建议执行以下命令:")
print(f"\033[93m{command}\033[0m") # 黄色显示
print("\n这个命令可能会修改你的系统设置或文件。")
print("请仔细检查命令内容!")
confirm = input("\n是否执行此命令? (y/N): ").strip().lower()
if confirm != 'y':
log_message("用户取消了命令执行")
print("命令已取消。")
sys.exit(0)
# 3. 执行命令
log_message("正在执行...")
output = run_command(command)
# 4. 显示结果
print("\n" + "="*50)
print(output)
if __name__ == "__main__":
main()
ai "查看磁盘使用情况" 就能用了,非常方便。pip install realtimestt即可完成安装。git clone https://github.com/omegaui/linux-voice-control.git,然后进入项目目录运行./install.sh安装依赖,最后编辑lvc - config.json文件进行配置,通过python main.py启动。--command 参数。这个参数可以让它在识别到语音后,自动运行一个指定的命令。ai_shell.py 已经可以正常运行。realtimestt --command "python /path/to/your/ai_shell.py \"%s\""
%s 这个占位符。RealtimeSTT 会把识别到的语音文字替换掉它,然后执行整个命令。python /path/to/your/ai_shell.py "查看端口8080的占用情况"ai_shell.py 脚本去执行import subprocess
import sys
def main():
print("语音AI助手已启动,正在等待指令...")
print("=" * 50)
while True:
# 读取来自RealtimeSTT的输入
user_input = sys.stdin.readline()
if not user_input:
break
user_input = user_input.strip()
if not user_input:
continue
print(f"\n你说: {user_input}")
print("正在处理...")
# 调用我们的AI脚本
result = subprocess.run(
["python", "/path/to/your/ai_shell.py", user_input],
capture_output=True,
text=True
)
# 显示结果
print("结果:")
if result.stdout:
print(result.stdout)
if result.stderr:
print(f"错误: {result.stderr}")
print("=" * 50)
if __name__ == "__main__":
main()
voice_agent.pypython voice_agent.pyrealtimestt --command "echo \"%s\" | python /path/to/your/voice_agent.py"
start_voice_ai.sh,然后双击运行它就行了。#!/bin/bash
# 请将下面的路径替换成你自己的脚本路径
AI_SHELL_PATH="/path/to/your/ai_shell.py"
VOICE_AGENT_PATH="/path/to/your/voice_agent.py"
# 检查脚本是否存在
if [ ! -f "$AI_SHELL_PATH" ]; then
echo "错误: 找不到 ai_shell.py 文件在路径: $AI_SHELL_PATH"
exit 1
fi
if [ ! -f "$VOICE_AGENT_PATH" ]; then
echo "错误: 找不到 voice_agent.py 文件在路径: $VOICE_AGENT_PATH"
exit 1
fi
# 启动 voice_agent.py 在一个新的终端窗口
echo "正在启动语音AI助手..."
gnome-terminal -- bash -c "python \"$VOICE_AGENT_PATH\"; exec bash"
# 给一点时间让终端窗口启动
sleep 2
# 启动 RealtimeSTT
echo "正在启动语音识别..."
realtimestt --command "echo \"%s\" | python \"$VOICE_AGENT_PATH\""
AI_SHELL_PATH 和 VOICE_AGENT_PATH 这两行的路径,改成你自己保存那两个Python脚本的实际位置start_voice_ai.shchmod +x start_voice_ai.sh 给它加上可执行权限start_voice_ai.sh 文件voice_agent.py 的完整脚本代码,它作为中间桥梁连接 RealtimeSTT 和我们的 AI 命令脚本:ai_shell.py 处理,并在同一个窗口显示所有结果AI_SHELL_PATH 替换为 ai_shell.py 的实际保存路径python3 改成 python 试试)chmod +x voice_agent.py 赋予执行权限start_voice_ai.sh 配合使用时,要保证路径一致API_KEY变量中;ai_shell.py脚本中,实现本地调用豆包API的功能了。如果过程中遇到某个步骤卡住,要不要我帮你整理一份「API Key获取常见问题排查表」?比如“找不到创建应用按钮”“提交后没生成API Key”等情况的解决办法。https://open.doubao.com可能已停止使用。以下是获取豆包API Key的最新操作指南(2025年10月更新):import os
from openai import OpenAI # 兼容OpenAI接口
# 配置火山引擎API Key和Base URL
os.environ["ARK_API_KEY"] = "your_ark_api_key"
client = OpenAI(base_url="https://ark.cn-beijing.volces.com/api/v3")
# 调用豆包模型
response = client.chat.completions.create(
model="doubao-seed-1-6-250615", # 模型ID
messages=[{"role": "user", "content": "你好,豆包!"}]
)
print(response.choices[0].message.content)
# 创建并编辑API密钥文件
nano ~/.doubao
your_api_key_here
your_secret_key_here
Ctrl+O保存,Ctrl+X退出),然后设置文件权限确保安全:chmod 600 ~/.doubao # 仅当前用户可读写
# 安装Python依赖
sudo apt update
sudo apt install -y python3 python3-pip python3-venv
# 安装RealtimeSTT
pip install realtimestt
# 安装requests库(用于API调用)
pip install requests
mkdir -p ~/voice_ai_assistant
cd ~/voice_ai_assistant
nano ai_shell.py创建并粘贴第一个脚本内容nano voice_agent.py创建并粘贴第二个脚本内容nano start_voice_ai.sh创建并粘贴第三个脚本内容voice_agent.py,将AI_SHELL_PATH修改为实际路径,例如:AI_SHELL_PATH = "/home/你的用户名/voice_ai_assistant/ai_shell.py"
start_voice_ai.sh,修改两个路径为实际路径:AI_SHELL_PATH="/home/你的用户名/voice_ai_assistant/ai_shell.py"
VOICE_AGENT_PATH="/home/你的用户名/voice_ai_assistant/voice_agent.py"
chmod +x start_voice_ai.sh
chmod +x ai_shell.py
chmod +x voice_agent.py
~/.doubao密钥文件~/voice_ai_assistant/start_voice_ai.sh
~/.doubao中的密钥是否正确,网络连接是否正常~/.doubao文件中,不会硬编码在脚本里,同时整个语音交互流程也更加流畅。PyAudio 时缺少依赖的系统库 PortAudio 导致的。解决方法很简单,先安装系统级的 PortAudio 开发包,再重新安装即可。# 安装 PortAudio 系统库(PyAudio 的依赖)
sudo apt update
sudo apt install -y portaudio19-dev
# 重新安装 RealtimeSTT(会自动处理 PyAudio 依赖)
pip install realtimestt
portaudio19-dev 包含了编译 PyAudio 所需的头文件(portaudio.h)和库文件,解决了报错中的 fatal error: portaudio.h: No such file or directory 问题。PyAudio 就能正常编译安装了。pip3 替代 pip(确保使用 Python3 的包管理器):pip3 install realtimestt
RealtimeSTT 已经安装成功了,不影响你后续使用语音输入功能。gradio、img2dataset、yt-dlp)和 RealtimeSTT 对同一包(如 websockets、requests)的版本要求,而非 RealtimeSTT 本身安装失败:Successfully installed realtimestt-0.3.104,说明 RealtimeSTT 已经正常装好,后续调用语音识别功能不受影响。gradio 做界面、yt-dlp 下载视频时),如果不常用这些工具,完全不用管。gradio、img2dataset 或 yt-dlp 时出现报错(比如“版本不兼容”),再针对性解决即可,推荐用 Python虚拟环境 隔离依赖,避免影响系统级包:# 创建虚拟环境(名字随便取,比如voice-env)
python3 -m venv ~/voice-env
# 激活虚拟环境
source ~/voice-env/bin/activate
RealtimeSTT:pip install realtimestt
RealtimeSTT 的依赖会被限制在虚拟环境里,不会和系统里的 gradio、yt-dlp 等工具冲突。RealtimeSTT,彻底避免依赖冲突问题。realtimestt 的可执行文件路径没被系统识别(pip 安装到了用户级目录,而非系统级目录),只需把路径添加到系统环境变量即可解决。pip install 时,因为系统权限限制,默认安装到了 用户专属目录(~/.local/bin),而这个目录默认没加入系统的 PATH 环境变量,所以终端找不到 realtimestt 命令。realtimestt 安装路径ls ~/.local/bin/realtimestt
~/.local/bin/realtimestt,说明文件存在,继续下一步;如果提示“不存在”,可重新用 pip install --user realtimestt 强制安装到用户目录。bash,配置文件是 ~/.bashrc):nano ~/.bashrc
export PATH="$HOME/.local/bin:$PATH"
Ctrl+O(确认保存)→ 按回车 → 按 Ctrl+X。source ~/.bashrc
realtimestt 的路径,说明成功:which realtimestt
~/.local/bin/realtimestt 即正常,此时再运行启动脚本:./start_voice_ai.sh
zsh(而非默认 bash),只需把步骤2中的 ~/.bashrc 换成 ~/.zshrc 即可,其他步骤完全一样。realtimestt 安装后没有生成直接可执行的命令文件(可能是包的安装结构问题),但我们可以通过 Python 模块调用方式 来运行它,绕过直接执行命令的限制。realtimestt 作为 Python 包,即使没有生成可执行文件,也可以通过 python3 -m realtimestt 的方式调用(这是 Python 包的标准运行方式)。我们只需修改启动脚本,用这种方式替代直接执行 realtimestt 命令即可。realtimestt 能否通过模块方式运行:python3 -m realtimestt --help
pip uninstall -y realtimestt
pip install --user realtimestt # 重新安装,确保完整
start_voice_ai.sh)realtimestt 的部分,替换为 python3 -m realtimestt。修改后的完整脚本如下:chmod +x start_voice_ai.sh # 确保权限
./start_voice_ai.sh # 启动脚本
python3 -m realtimestt 是 Python 调用模块的标准方式,即使没有生成可执行文件,只要包安装正确,就能运行其内部的命令行功能。realtimestt 模块是否存在(通过 import realtimestt),避免“找不到命令”的错误。python3 -m realtimestt 测试,看是否有麦克风权限提示或其他错误(通常是麦克风未授权或模型下载失败)。需要的话,我可以帮你分析具体错误信息。pip --user 把 realtimestt 安装到了用户专属的 Python 模块目录,但你的系统 Python 没把这个目录加入“模块搜索路径”,所以找不到它。我们需要手动把安装路径添加到 Python 的搜索范围里。realtimestt 的实际安装路径find ~/.local -name "realtimestt" -type d
site-packages 下的 realtimestt 目录):/home/nick/.local/lib/python3.10/site-packages/realtimestt
~/.local/lib/python3.10/site-packages),后面要用到。python3 -c "import sys; print('\n'.join(sys.path))"
~/.local/lib/python3.10/site-packages,就说明 Python 确实没搜索这个目录,这就是问题根源。*.pth 文件,让 Python 每次启动都自动加载这个路径。具体命令如下:# 把用户目录下的 site-packages 路径写入 Python 的配置文件
echo "$HOME/.local/lib/python3.10/site-packages" > "$HOME/.local/lib/python3.10/site-packages/user_paths.pth"
~/.local/lib/python3.10/site-packages 是否已经在 sys.path 里了:python3 -c "import sys; print('$HOME/.local/lib/python3.10/site-packages' in sys.path)"
True,说明添加成功;如果是 False,重新执行步骤3的第1条命令。realtimestt 是否能调用python3 -m realtimestt --help
realtimestt 的帮助信息(比如各种参数说明),就说明问题解决了!此时再运行启动脚本:./start_voice_ai.sh
sys.path 列表里的目录中搜索;pip --user 安装的包默认放在 ~/.local/lib/[Python版本]/site-packages,但部分系统不会自动把这个目录加入 sys.path;user_paths.pth 文件,是 Python 的“路径配置文件”,只要放在 site-packages 里,Python 启动时就会自动读取并把里面的路径加入 sys.path。find 命令的输出结果,我帮你调整路径。find 命令没有输出来看,realtimestt 实际没有安装到 ~/.local 目录(之前的 pip install 虽然显示“成功”,但可能只是缓存或路径不匹配导致的假象)。我们需要先找到 pip 实际的安装目录,再针对性解决。pip 对应的 Python 版本(关键!)pip 和你运行的 python3 对应不同的 Python 版本(比如系统有 Python3.8 和 3.10,pip 装到了 3.8,而 python3 是 3.10)。pip 对应的 Python 版本:pip --version
pip 24.0 from /home/nick/.local/lib/python3.10/site-packages/pip (python 3.10)
/home/nick/.local/lib/python3.10/site-packages)。realtimestt 实际安装路径pip show 命令强制查看 realtimestt 的安装信息(即使 find 找不到,pip 也能显示它记录的路径):pip show realtimestt
Location 字段):Name: realtimestt
Version: 0.3.104
Location: /home/nick/.local/lib/python3.10/site-packages # 这是实际安装路径
Requires: PyAudio, faster-whisper, ...
Location 字段为空或提示“WARNING: Package(s) not found: realtimestt”,说明 安装根本没成功,直接跳步骤3重新安装;Location 有路径,先记下来,然后执行 ls [Location路径]/realtimestt 确认目录是否存在(比如 ls /home/nick/.local/lib/python3.10/site-packages/realtimestt)。realtimestt(避免缓存问题)# 1. 彻底卸载(即使提示没安装也执行)
pip uninstall -y realtimestt
# 2. 清理 pip 缓存(避免用旧的损坏安装包)
pip cache purge
# 3. 重新安装,加上 -vv 显示详细日志(方便排查问题)
pip install --user -vv realtimestt
Installing collected packages: realtimestt 后面的路径,确认它安装到了步骤1中 pip --version 显示的 site-packages 目录。# 把路径换成步骤1中 pip --version 显示的 site-packages 路径
ls ~/.local/lib/python3.10/site-packages/realtimestt
__init__.py、cli.py 等),说明安装成功了!此时再测试模块调用:python3 -m realtimestt --help
site-packages,所有用户都能调用):# 卸载用户级安装(避免冲突)
pip uninstall -y realtimestt
# 系统级安装(需要输入密码)
sudo pip install realtimestt
python3 -m realtimestt --help
sys.path 里,基本不会出现“找不到”的问题。pip show realtimestt 还是提示“找不到包”,可以告诉我步骤1中 pip --version 的输出结果,我帮你进一步定位问题(比如是否需要指定 pip3 而非 pip)。realtimestt 确实安装到了 /home/nick/.local/lib/python3.10/site-packages 目录,但 Python 3.10 没把这个目录加入模块搜索路径,导致找不到它。解决方法很明确:手动把这个路径添加到 Python 的搜索范围。python3 -c "import sys; print('/home/nick/.local/lib/python3.10/site-packages' in sys.path)"
False:说明 Python 确实没搜索这个目录,直接执行步骤2;True:可能是其他问题(比如文件损坏),跳步骤3。# 进入 Python 的 site-packages 目录
cd /home/nick/.local/lib/python3.10/site-packages
# 创建路径配置文件(名字固定为 user_paths.pth)
echo "/home/nick/.local/lib/python3.10/site-packages" > user_paths.pth
python3 -c "import sys; print('/home/nick/.local/lib/python3.10/site-packages' in sys.path)"
True,然后测试 realtimestt 是否能调用:python3 -m realtimestt --help
# 修复用户目录下 Python 模块的权限
chmod -R 755 /home/nick/.local/lib/python3.10/site-packages/realtimestt
python3 -m realtimestt --help。~/.local/lib/pythonX.Y/site-packages 会自动被 Python 识别为用户级模块目录,但某些系统(尤其是自定义过 Python 环境的)可能会丢失这个配置。我们手动创建的 user_paths.pth 文件,就是强制告诉 Python“去这个目录找模块”。realtimestt 应该就能正常调用了,此时再运行 ./start_voice_ai.sh 即可启动语音助手。/home/nick/.local/lib/python3.10/site-packages路径(sys.path里有),pip show也确认realtimestt安装在这个目录,但执行python3 -m realtimestt还是提示找不到模块。这说明可能是realtimestt包本身的结构问题 —— 比如没有正确的__main__.py文件,导致 Python 无法将其识别为可执行模块。realtimestt包的内部结构,看看是否有__main__.py(这是 Python 模块可被-m调用的关键文件)。所以第一步应该让用户查看该目录下是否有__main__.py,或者是否有cli.py等可执行入口文件。from RealtimeSTT import AudioToTextRecorder),而不是依赖-m模块调用。之前的思路是用-m调用,但如果包本身不支持这种方式,就需要换个思路:直接写一个简单的 Python 脚本,通过 API 调用 RealtimeSTT,替代realtimestt命令,这样就能绕过-m调用的问题。voice_input.py),用 RealtimeSTT 的 API 实现语音识别,并将结果传递给voice_agent.py。这样既符合官方推荐的用法,又能解决当前 “找不到模块” 的问题。start_voice_ai.sh需要修改,不再调用realtimestt命令,而是运行这个新的中间脚本。同时,确保新脚本能正确接收语音输入,并将转文字结果传给voice_agent.py,保持整个流程的连贯性。realtimestt的 API 是否能正常导入,先让用户执行简单的导入命令(python3 -c "from RealtimeSTT import AudioToTextRecorder; print('Import success')"),确认 API 可用,排除包损坏的可能。如果导入成功,说明包本身没问题,只是不支持-m调用;如果导入失败,可能是包安装不完整,需要重新安装。realtimestt,核心原因是 realtimestt 包本身不支持 python3 -m 模块调用方式(可能缺少 __main__.py 入口文件)。但我们可以绕开这个问题,直接用它的 Python API 写一个简单的语音输入脚本,替代 realtimestt 命令,这样更符合它的官方用法。realtimestt API 是否能正常导入(关键!)python3 -c "from RealtimeSTT import AudioToTextRecorder; print('RealtimeSTT 导入成功!')"
RealtimeSTT 导入成功!:说明包没问题,直接进入步骤2;pip uninstall -y realtimestt && pip install --user realtimestt 重新安装,再试一次。realtimestt 命令的 Python 脚本realtimestt 的官方 API,写一个能接收语音、转文字并传给 voice_agent.py 的脚本(命名为 voice_input.py),彻底绕开 python3 -m 调用问题。voice_input.py 脚本:nano ~/voice_ai_assistant/voice_input.py
VOICE_AGENT_PATH 为你实际的 voice_agent.py 路径):from RealtimeSTT import AudioToTextRecorder
import subprocess
import os
# 替换为你的 voice_agent.py 实际路径
VOICE_AGENT_PATH = "/home/nick/voice_ai_assistant/voice_agent.py"
def process_text(text):
"""将语音转的文字传给 voice_agent.py"""
if not text.strip():
return # 忽略空输入
print(f"\n识别到语音:{text}")
# 调用 voice_agent.py 并传递文字参数
subprocess.run(
["python3", VOICE_AGENT_PATH, text],
capture_output=False, # 显示输出,方便调试
text=True
)
if __name__ == '__main__':
print("语音识别已启动,开始说话...(按 Ctrl+C 退出)")
# 初始化语音 recorder,用默认配置
recorder = AudioToTextRecorder(
model="tiny", # 小模型,速度快,适合CPU
language="zh", # 中文识别(根据需要调整,如"en"为英文)
spinner=True # 显示状态动画
)
try:
# 循环监听语音,识别后调用 process_text
while True:
recorder.text(process_text)
except KeyboardInterrupt:
print("\n语音识别已退出")
recorder.shutdown() # 安全关闭 recorder
start_voice_ai.shrealtimestt 命令,现在换成调用我们新写的 voice_input.py。修改后的完整启动脚本如下:nano ~/voice_ai_assistant/start_voice_ai.sh
#!/bin/bash
# 替换为你的脚本实际路径
AI_SHELL_PATH="/home/nick/voice_ai_assistant/ai_shell.py"
VOICE_AGENT_PATH="/home/nick/voice_ai_assistant/voice_agent.py"
VOICE_INPUT_PATH="/home/nick/voice_ai_assistant/voice_input.py" # 新增的脚本路径
# 检查所有脚本是否存在
if [ ! -f "$AI_SHELL_PATH" ]; then
echo "错误: 找不到 ai_shell.py 文件在路径: $AI_SHELL_PATH"
exit 1
fi
if [ ! -f "$VOICE_AGENT_PATH" ]; then
echo "错误: 找不到 voice_agent.py 文件在路径: $VOICE_AGENT_PATH"
exit 1
fi
if [ ! -f "$VOICE_INPUT_PATH" ]; then
echo "错误: 找不到 voice_input.py 文件在路径: $VOICE_INPUT_PATH"
exit 1
fi
# 检查 API 密钥文件
if [ ! -f "$HOME/.doubao" ]; then
echo "错误: 找不到 API 密钥文件 $HOME/.doubao"
exit 1
fi
# 检查 RealtimeSTT 是否能正常导入
if ! python3 -c "from RealtimeSTT import AudioToTextRecorder" &> /dev/null; then
echo "错误: RealtimeSTT 模块导入失败"
echo "请重新安装: pip uninstall -y realtimestt && pip install --user realtimestt"
exit 1
fi
# 启动 voice_agent.py(显示结果的窗口)
echo "正在启动语音AI助手(结果窗口)..."
gnome-terminal --title "语音AI助手-结果" -- bash -c "python3 \"$VOICE_AGENT_PATH\"; exec bash"
# 等待 2 秒,确保结果窗口启动完成
sleep 2
# 启动语音输入脚本(核心:监听语音并传递给 agent)
echo "正在启动语音识别(输入窗口)..."
gnome-terminal --title "语音AI助手-语音输入" -- bash -c "python3 \"$VOICE_INPUT_PATH\"; exec bash"
# 赋予所有脚本执行权限
chmod +x ~/voice_ai_assistant/*.sh
chmod +x ~/voice_ai_assistant/*.py
# 启动脚本
~/voice_ai_assistant/start_voice_ai.sh
realtimestt 官方推荐的用法是 API 导入(from RealtimeSTT import AudioToTextRecorder),而不是 python3 -m 命令调用——之前的问题正是强行用了不支持的调用方式;voice_input.py 直接用它的 API 实现语音识别,识别到文字后再传给 voice_agent.py,完全符合官方设计,避免了 -m 调用的坑;voice_agent.py),一个处理语音输入(voice_input.py),流程和之前一致,但更稳定。# 确保当前用户在音频组(需要sudo权限)
sudo usermod -aG audio $USER
# 录制5秒音频(按Ctrl+C结束)
arecord -d 5 test_mic.wav
# 播放录音,确认是否有声音
aplay test_mic.wav
nano ~/.asoundrc
pcm.!default {
type plug
slave.pcm "dmix"
}
ctl.!default {
type hw
card 0
}
sudo alsa force-reload
# 升级optree到最新版本,消除警告
pip install --upgrade 'optree>=0.13.0'
voice_input.py 中的模型参数,将 model="tiny" 改为更轻量的模型(如果有的话),或增加延迟容忍度(不影响基本使用,可忽略)。~/voice_ai_assistant/start_voice_ai.sh
voice_agent.py 处理。sudo apt update && sudo apt upgrade -ysudo apt install -y alsa-utils pulseaudiorealtimestt无法正确访问麦克风。解决方法需要从音频服务层面入手,而非单纯修改ALSA配置:# 停止并重启Pulseaudio服务
pulseaudio --kill
pulseaudio --start
realtimestt默认可能直接调用ALSA,而你的系统更适合用Pulseaudio。修改voice_input.py,在初始化录音器时指定音频后端为Pulseaudio:voice_input.py:nano ~/voice_ai_assistant/voice_input.py
recorder = AudioToTextRecorder(这一行,添加audio_backend="pulse"参数:recorder = AudioToTextRecorder(
model="tiny",
language="zh",
spinner=True,
audio_backend="pulse" # 新增:强制使用Pulseaudio
)
# 查看录音设备列表(确认设备路径,如hw:0,0)
arecord -l
# 修复常见录音设备的权限(以hw:0为例,根据上一步输出调整)
sudo chmod 666 /dev/snd/pcmC0D0c # 替换为你的录音设备路径
# 彻底重新安装音频相关组件
sudo apt update
sudo apt purge -y alsa-base pulseaudio
sudo apt install -y alsa-base pulseaudio
sudo alsa force-reload
# 重启电脑(必须重启才能生效)
sudo reboot
~/voice_ai_assistant/start_voice_ai.sh
arecord -l 的输出来看,你的录音设备是 card 1, device 0(对应名称 ALC256 Analog),因此设备路径不是 pcmC0D0c,而是 pcmC1D0c(C1 对应 card 1,D0 对应 device 0)。ls /dev/snd/pcmC1D0c # 检查设备是否存在
(/dev/snd/pcmC1D0c),说明路径正确。sudo chmod 666 /dev/snd/pcmC1D0c
sudo chmod 666 /dev/snd/controlC1 # 对应 card 1 的控制设备
pavucontrol
~/voice_ai_assistant/start_voice_ai.sh
realtimestt 官方最简化的测试脚本,排除所有其他干扰(比如不关联 voice_agent.py),先让语音转文字单独跑通。test_realtimestt.py 的文件,内容只保留核心功能(不依赖任何其他脚本):nano ~/test_realtimestt.py
from RealtimeSTT import AudioToTextRecorder
# 定义语音识别后的文字处理函数(仅打印文字)
def print_transcription(text):
if text.strip(): # 只打印非空内容
print(f"\n【识别结果】:{text}")
if __name__ == '__main__':
print("=== 简化语音转文字测试 ===")
print("1. 等待10秒加载模型(首次运行会下载小模型,耐心等)")
print("2. 模型加载完后,直接说话(说完会自动识别)")
print("3. 按 Ctrl+C 退出\n")
# 初始化录音器:用最小中文模型,强制Pulseaudio音频后端(适配你的设备)
recorder = AudioToTextRecorder(
model="tiny.en", # 先测英文模型(体积小、下载快),后续再换中文
# model="tiny", # 若要直接测中文,把上面注释,用这个(需下载稍大模型)
language="en", # 对应模型语言(英文填en,中文留空或填zh)
audio_backend="pulse", # 强制用Pulseaudio,适配你的声卡
spinner=True, # 显示加载状态,方便判断是否在运行
device="cpu" # 强制用CPU(避免GPU配置干扰)
)
try:
# 循环监听语音,识别后调用print_transcription打印文字
while True:
recorder.text(print_transcription)
except KeyboardInterrupt:
print("\n\n程序已退出")
recorder.shutdown() # 安全关闭
arecord -l 可知,你的录音设备是 card 1, device 0,先给它正确授权:# 给card 1的录音设备和控制设备开权限
sudo chmod 666 /dev/snd/pcmC1D0c
sudo chmod 666 /dev/snd/controlC1
# 重启Pulseaudio,确保设备被正确识别
pulseaudio --kill
pulseaudio --start
python3 ~/test_realtimestt.py
tiny.en 模型(约几十MB),终端会显示“Downloading...”,耐心等它完成(出现“speak now”或“语音识别已就绪”类似提示,说明加载完)。【识别结果】:Hello, test voice to text(中文模型则说中文,如“测试语音转文字”)。~/.cache/huggingface/hub 目录。test_realtimestt.py 后,说话能在终端看到对应文字,就说明“语音输入→文字输出”这一步走通了。后续再把这个功能和之前的脚本关联,现在先聚焦解决这一个核心点。realtimestt 版本太旧(0.3.104),不支持 audio_backend 这个参数(该参数是后期版本新增的)。我们需要先升级到最新版本,再简化脚本去掉不兼容的参数。realtimestt 到最新版pip install --user --upgrade realtimestt
test_realtimestt.py:nano ~/test_realtimestt.py
audio_backend 参数,用旧版本兼容的方式):from RealtimeSTT import AudioToTextRecorder
# 仅打印识别到的文字
def print_transcription(text):
if text.strip():
print(f"\n【识别结果】:{text}")
if __name__ == '__main__':
print("=== 简化语音转文字测试 ===")
print("1. 等待模型加载(首次运行会下载,耐心等)")
print("2. 模型加载完后,说话即可自动识别")
print("3. 按 Ctrl+C 退出\n")
# 初始化录音器(用旧版本兼容的参数)
recorder = AudioToTextRecorder(
model="tiny", # 中文小模型(约1GB,下载稍慢但支持中文)
language="zh", # 明确指定中文
spinner=True, # 显示加载状态
device="cpu" # 强制CPU运行,避免GPU问题
)
try:
# 循环监听语音
while True:
recorder.text(print_transcription)
except KeyboardInterrupt:
print("\n程序已退出")
recorder.shutdown()
python3 ~/test_realtimestt.py
tiny 中文模型(约1GB),终端会显示进度条,耐心等待(中途不要关闭,否则需重新下载)。~/.cache/huggingface/hub 目录(模型地址:faster-whisper-tiny)。realtimestt 单独工作,只要说话能在终端看到中文文字,就说明语音转文字功能通了。后续再逐步整合其他脚本,现在专注解决这个基础问题即可。有任何新的报错,直接告诉我具体内容。test_realtimestt.py,添加 input_device_index=1 参数(对应你的 card 1 设备):nano ~/test_realtimestt.py
from RealtimeSTT import AudioToTextRecorder
# 只打印识别结果
def print_transcription(text):
if text.strip():
print(f"\n【识别结果】:{text}")
if __name__ == '__main__':
print("=== 简化语音转文字测试 ===")
print("1. 等待模型加载(首次运行下载,耐心等)")
print("2. 加载完后说话,自动识别中文")
print("3. 按 Ctrl+C 退出\n")
# 关键:input_device_index=1(对应你的 card 1 录音设备)
recorder = AudioToTextRecorder(
model="tiny", # 中文小模型
language="zh", # 中文识别
input_device_index=1, # 强制用 card 1 设备(你的麦克风)
device="cpu", # 避免GPU干扰
spinner=True
)
try:
while True:
recorder.text(print_transcription)
except KeyboardInterrupt:
print("\n程序已退出")
recorder.shutdown()
pulseaudio --kill && pulseaudio --start
python3 ~/test_realtimestt.py
card 0(但你的麦克风在 card 1),导致找不到设备,所以ALSA报错;input_device_index=1 直接告诉脚本“用第1个录音设备”(对应 arecord -l 里的 card 1),跳过自动识别的错误;~/.cache/huggingface/hub(模型地址:faster-whisper-tiny);【识别结果】:测试语音转文字 就成功了。input_device_index=1 后一定能访问到。realtimestt 对新手来说,环境配置和依赖问题确实有点繁琐。sudo apt update
sudo apt install -y git build-essential
# 克隆代码库
git clone https://github.com/ggerganov/whisper.cpp.git
cd whisper.cpp
# 编译(会生成命令行工具)
make
# 下载一个小的中文模型(约150MB)
bash ./models/download-ggml-model.sh base-zh
# 录制3秒音频
arecord -d 3 -r 16000 -c 1 -f S16_LE test.wav
# 用Whisper.cpp识别音频
./main -m models/ggml-base-zh.bin -f test.wav -l zh
ai_shell.py 处理-D plughw:1,0 强制指定设备,避免再次出现识别不到设备的问题。同时,脚本里要加入简单的错误处理,比如录音失败时提示检查设备,模型不存在时提示下载。whisper.cpp 目录,确认文件都在:cd ~/whisper.cpp # 进入你之前克隆的目录
ls -l main models/ggml-base-zh.bin # 检查编译好的工具和中文模型
main(可执行文件)和 ggml-base-zh.bin(中文模型),说明环境没问题,直接下一步;make 和 bash ./models/download-ggml-model.sh base-zh 命令。voice2text.sh)whisper.cpp 目录下新建脚本:nano ~/whisper.cpp/voice2text.sh
#!/bin/bash
# 中文语音转文字脚本(基于 Whisper.cpp)
# 核心:录音→识别→输出文字,无Python依赖
# ===================== 配置(根据你的设备调整)=====================
# 录音设备:plughw:1,0 对应你的 card 1(之前 arecord -l 查的),不要改!
RECORD_DEVICE="plughw:1,0"
# 临时录音文件(识别完自动删除)
TEMP_WAV="temp_voice.wav"
# Whisper.cpp 路径(如果你改了目录,这里要对应改)
WHISPER_MAIN="./main"
# 中文模型路径
WHISPER_MODEL="models/ggml-base-zh.bin"
# ==================================================================
# 检查 Whisper 环境是否正常
check_env() {
if [ ! -f "$WHISPER_MAIN" ]; then
echo "错误:没找到 Whisper 可执行文件 $WHISPER_MAIN"
echo "请先在 whisper.cpp 目录执行 make 编译"
exit 1
fi
if [ ! -f "$WHISPER_MODEL" ]; then
echo "错误:没找到中文模型 $WHISPER_MODEL"
echo "请执行 bash ./models/download-ggml-model.sh base-zh 下载"
exit 1
fi
}
# 录音功能(按 Enter 开始,按 Ctrl+C 结束)
record_voice() {
echo -e "\n=== 准备录音 ==="
echo "提示:按 Enter 开始录音,说完后按 Ctrl+C 结束"
read -r # 等待用户按 Enter
echo "正在录音...(按 Ctrl+C 停止)"
# 关键:用指定设备录音,参数匹配 Whisper 要求(16000采样率、单声道)
arecord -D "$RECORD_DEVICE" -r 16000 -c 1 -f S16_LE -q "$TEMP_WAV"
}
# 识别功能(调用 Whisper.cpp 识别中文)
recognize_voice() {
if [ ! -f "$TEMP_WAV" ]; then
echo "错误:录音文件不存在,可能录音失败了"
return 1
fi
echo -e "\n=== 正在识别文字 ==="
# 调用 Whisper 识别,只输出干净的文字结果(过滤掉日志)
"$WHISPER_MAIN" -m "$WHISPER_MODEL" -f "$TEMP_WAV" -l zh -q \
| grep -A 1 "Transcription:" | tail -n 1 | sed 's/^[ \t]*//'
}
# 主流程
main() {
check_env # 先检查环境
while true; do
# 1. 录音
record_voice
# 2. 识别
recognize_voice
# 3. 清理临时文件
rm -f "$TEMP_WAV"
# 询问是否继续
echo -e "\n是否继续识别?(y=继续,n=退出)"
read -r choice
if [ "$choice" != "y" ]; then
echo "再见!"
exit 0
fi
done
}
# 启动脚本
main
# 进入 whisper.cpp 目录
cd ~/whisper.cpp
# 赋予权限
chmod +x voice2text.sh
# 启动脚本
./voice2text.sh
=== 正在识别文字 ===
测试一下语音识别是否正常
RECORD_DEVICE="plughw:1,0" 直接绑定你的 card 1 麦克风,避开自动识别的坑;RECORD_DEVICE 改成 plughw:1(去掉后面的 ,0)试试;bash ./models/download-ggml-model.sh base-zh)。ai_shell.py 关联,实现语音控制命令,现在先享受这个稳定的基础功能~