当前位置: 代码网 > 服务器>服务器>Linux > linux系统(ubuntu)调用科大讯飞SDK实现语音识别

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

2024年08月01日 Linux 我要评论
我写了一个调用的代码,可以不在键入0 1 ,而直接开始识别吗,并将识别结果保存在result.txt文件中。进入sample目录的iat_online_record_sample目录下,运行下面的命令。此时将得到一个压缩包,选择的功能不同,文件名也不同,将这个压缩包放在ubuntu中。在测试之前,先检查自己的麦克风,以及虚拟机Linux的联网状态。点击左侧的语音听写,右边下滑选择Linux,点击下载。选择Linux平台,普通版本,语音听写,SDK下载。如果出现这个错误的话需要将下面这个路径的。

1. 科大讯飞官网

登录注册实名制
在这里插入图片描述

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

点击左侧的语音听写,右边下滑选择linux,点击下载
在这里插入图片描述
选择linux平台,普通版本,语音听写,sdk下载
在这里插入图片描述
此时将得到一个压缩包,选择的功能不同,文件名也不同,将这个压缩包放在ubuntu中
在这里插入图片描述

3. sdk包的处理

新建一个文件夹将压缩包中的文件放进去
进入sample目录的iat_online_record_sample目录下,运行下面的命令

source 64bit_make.sh

在这里插入图片描述

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

sudo apt-get install libasound2-dev

4. 检查环境

在测试之前,先检查自己的麦克风,以及虚拟机linux的联网状态。
在这里插入图片描述
在这里插入图片描述

5.语音识别

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

./iat_online_record_sample

在这里插入图片描述

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

在这里插入图片描述
result.txt如下:
在这里插入图片描述voice.py代码如下:

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. 问题

有一个可能出现的问题,

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==路径下

在这里插入图片描述
执行下面的命令

sudo cp libmsc.so /usr/local/lib
sudo ldconfig

在这里插入图片描述
不出意外的话可以解决这个问题。

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

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com