linux系统(ubuntu)调用科大讯飞SDK实现语音识别

1. 科大讯飞官网

登录注册实名制

2. 点击控制台,创建应用

点击左侧的语音听写,右边下滑选择Linux,点击下载

选择Linux平台,普通版本,语音听写,SDK下载

此时将得到一个压缩包,选择的功能不同,文件名也不同,将这个压缩包放在ubuntu中

3. SDK包的处理

新建一个文件夹将压缩包中的文件放进去

进入sample目录的iat_online_record_sample目录下,运行下面的命令

bash 复制代码
source 64bit_make.sh

如果提示"alsa/asound.h:没有那个文件或目录"。解决办法:

bash 复制代码
sudo apt-get install libasound2-dev

4. 检查环境

在测试之前,先检查自己的麦克风,以及虚拟机Linux的联网状态。

5.语音识别

在bin目录下执行对应的可执行文件了

bash 复制代码
./iat_online_record_sample

我写了一个调用的代码,可以不在键入0 1 ,而直接开始识别吗,并将识别结果保存在result.txt文件中

result.txt如下:
voice.py代码如下:

python 复制代码
import subprocess
import multiprocessing
import time

def run_iat_online_record_sample(queue):
    process = subprocess.Popen(["./bin/iat_online_record_sample"], 
                               stdout=subprocess.PIPE, 
                               stdin=subprocess.PIPE, 
                               stderr=subprocess.PIPE, 
                               )
    
    # Communicate with the process
    stdout, _ = process.communicate(input=b"0\n1\n")
    
    # Put the result into the queue
    queue.put(stdout.decode('utf-8'))

def main():
    while True:
        # Create a queue for communication between processes
        queue = multiprocessing.Queue()
        
        # Start the process
        process = multiprocessing.Process(target=run_iat_online_record_sample, args=(queue,))
        process.start()
        
        # Wait for the process to finish and get the result from the queue
        process.join()
        result = queue.get()
        
        # Print the result
        print("Result:", result)
        
        # Save the result to a text file, clearing the file first
        with open("result.txt", "w") as f:
            f.write(result)
        
        # Ask user whether to continue recognition
        continue_recognition = input("是否继续识别? (0: 结束, 1: 继续): ")
        if continue_recognition == "0":
            break

if __name__ == "__main__":
    main()

6. 问题

有一个可能出现的问题,

bash 复制代码
User
ubuntu22@ubuntu22-virtual-machine:~/ros2_ws/voice_ros2/bin$ ./iat_online_record_sample 
./iat_online_record_sample: error while loading shared libraries: libmsc.so: cannot open shared object file: No such file or directory

如果出现这个错误的话需要将下面这个路径的libmsc.so文件复制到==/usr/local/lib==路径下

执行下面的命令

bash 复制代码
sudo cp libmsc.so /usr/local/lib
sudo ldconfig

不出意外的话可以解决这个问题。

如果遇到其他错误代码请查看

相关推荐
刚入门的大一新生6 分钟前
Linux-进程间通信2
linux·运维·服务器
电科_银尘10 分钟前
【深度学习项目实战·02】Linux服务器环境搭建:从SSH登录到稳定运行项目
linux·服务器·深度学习
运维小斌1 小时前
麒麟 V10 部署 OceanBase:故障速查与验收清单
linux·数据库·oceanbase·麒麟
水饺编程1 小时前
第2章:Linux 基础,在 root 中创建用户账号
linux·c语言·汇编·1024程序员节
叼烟扛炮1 小时前
Linux 学习笔记(四):文件检索与管道重定向
linux·笔记·学习
帷幕落秋3 小时前
Linux 网络基础
linux
高晶3 小时前
ARM 嵌入式 Linux 命令系统 BusyBox 实战指南
linux·设计模式·程序员
祥Sir的SRE笔记4 小时前
CPU 100% 不一定是故障:压测打满、业务饱和、突变打满的判断与排查
linux·面试·性能优化·dba·sre·故障定位·性能排查
郝亚军4 小时前
在win11上用openssl生成私钥、再从私钥导出公钥、...
linux·运维·服务器
一个风轻云淡4 小时前
从 int $0x80 到 iret:用 gdb 把 getpid 走一遍
linux·c语言·开发语言·汇编