NVIDIA AI-AGENT夏季训练营( RAG智能对话机器人)

项目名称:智能音乐平台语音识别与分析系统

报告日期:2024年8月18日

项目负责人:TIANL

项目概述:

本音乐平台致力于通过语音识别技术分析学习者的语音,判断其学习状态是否积极,系统据此提供智能化提示。帮助学习者特别是初级技能人员提高学习热情并增加其练习的持续时间。

技术方案与实施步骤:
  1. 模型选择:本系统选择了基于深度学习的英伟达NIM平台和微软的phi-3-voice,能更准确地识别语音中的关键词和行为倾向,为学习者提供建议。
  2. 数据的构建:数据构建过程包括收集学习者的语音数据、标注行为变化、进行特征提取和向量化处理等。系统整合了语音识别、行为分析和学习建议等生成等模块,实现了从语音输入到学习建议输出的智能化生成模式。
  3. 功能整合:采用深度学习技术来提高数据的表达能力和模型的泛化能力。利用知识库,构建一个AI助教智能助手等。使用Gradio创建聊天机器人界面,包括一个文本输入框、一个音频输入框和一个发送按钮。用户可以在文本输入框中输入问题,然后点击发送按钮将问题发送给聊天机器人。聊天机器人会根据用户输入的文本生成回复,并将回复显示在界面上。
实施步骤:
  1. 环境搭建:配置Python环境,安装 .NET 8 (下载地址 [https://dotnet.microsoft.com/](https://dotnet.microsoft.com/)),安装 Visual Studio Code,安装 Visual Studio Code 插件 (.NET Extension Pack 和 Python, Jupyter ),安装 Python 库 - Jupyter Notebook安装语音处理和机器学习相关库。
  2. 代码实现:实现语音信号预处理、模型训练、行为分析和学习建议生成等关键智能功能。
  3. 测试与调优:设计测试用例并测试系统,调优模型参数。
  4. 集成与部署:将语音识别和行为分析、建议等功能模块部署到Web或移动平台。
项目成果与展示:
  1. 应用场景展示: 通过语音识别技术分析学习者的语音

# ! pip install gradio

# ! pip install openai-whisper==20231117 

# ! pip install ffmpeg==1.4

# ! conda install ffmpeg -y

# ! pip install edge-tts

# ! pip install transformers

# ! pip install openai

1 创建Python环境

首先需要安装Miniconda:

根据自己的网络情况从下面的地址下载:

miniconda官网地址:https://docs.conda.io/en/latest/miniconda.html

清华大学镜像地址: https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/

安装完之后,打开Anaconda Powershell:

在打开的终端中按照下面的步骤执行,配置环境:

创建python 3.8虚拟环境

conda create --name ai_endpoint python=3.8

进入虚拟环境

conda activate ai_endpoint

安装nvidia_ai_endpoint工具

pip install langchain-nvidia-ai-endpoints 

安装Jupyter Lab

pip install jupyterlab

安装langchain_core

pip install langchain_core

安装langchain

pip install langchain

安装matplotlib

pip install matplotlib

安装Numpy

pip install numpy

安装faiss, 这里如果没有GPU可以安装CPU版本

pip install faiss-cpu==1.7.2

安装OPENAI库

pip install openai

2.利用Jupyter Lab打开课件执行,在上面打开的终端中, 输入以下命令:

jupyter-lab

利用Jupyter 打开课件

判断其学习状态是否积极,系统据此提供智能化提示。

def calculate_rate_string(input_value):

    rate = (input_value - 1) * 100

    sign = '+' if input_value >= 1 else '-'

    return f"{sign}{abs(int(rate))}"

def make_chunks(input_text, language):

    language="English"

    if language == "English":

      temp_list = input_text.strip().split(".")

      filtered_list = [element.strip() + '.' for element in temp_list[:-1] if element.strip() and element.strip() != "'" and element.strip() != '"']

      if temp_list[-1].strip():

          filtered_list.append(temp_list[-1].strip())

      return filtered_list

import re

import uuid

def tts_file_name(text):

    if text.endswith("."):

        text = text[:-1]

    text = text.lower()

    text = text.strip()

    text = text.replace(" ","_")

    truncated_text = text[:25] if len(text) > 25 else text if len(text) > 0 else "empty"

    random_string = uuid.uuid4().hex[:8].upper()

    file_name = f"./content/edge_tts_voice/{truncated_text}_{random_string}.mp3"

    return file_name

from pydub import AudioSegment

import shutil

import os

def merge_audio_files(audio_paths, output_path):

    # Initialize an empty AudioSegment

    merged_audio = AudioSegment.silent(duration=0)

    # Iterate through each audio file path

    for audio_path in audio_paths:

        # Load the audio file using Pydub

        audio = AudioSegment.from_file(audio_path)

        # Append the current audio file to the merged_audio

        merged_audio += audio

    # Export the merged audio to the specified output path

    merged_audio.export(output_path, format="mp3")

def edge_free_tts(chunks_list,speed,voice_name,save_path):

  # print(chunks_list)

  if len(chunks_list)>1:

    chunk_audio_list=[]

    if os.path.exists("./content/edge_tts_voice"):

      shutil.rmtree("./content/edge_tts_voice")

    os.mkdir("./content/edge_tts_voice")

    k=1

    for i in chunks_list:

      print(i)

      edge_command=f'edge-tts  --rate={calculate_rate_string(speed)}% --voice {voice_name} --text "{i}" --write-media ./content/edge_tts_voice/{k}.mp3'

      print(edge_command)

      var1=os.system(edge_command)

      if var1==0:

        pass

      else:

        print(f"Failed: {i}")

      chunk_audio_list.append(f"./content/edge_tts_voice/{k}.mp3")

      k+=1

    # print(chunk_audio_list)

    merge_audio_files(chunk_audio_list, save_path)

  else:

    edge_command=f'edge-tts  --rate={calculate_rate_string(speed)}% --voice {voice_name} --text "{chunks_list[0]}" --write-media {save_path}'

    print(edge_command)

    var2=os.system(edge_command)

    if var2==0:

      pass

    else:

      print(f"Failed: {chunks_list[0]}")

  return save_path

# text = "This is Microsoft Phi 3 mini 4k instruct Demo" Simply update the text variable with the text you want to convert to speech

text = 'This is Microsoft Phi 3 mini 4k instruct Demo'  # @param {type: "string"}

Language = "English" # @param ['English']

# Gender of voice simply change from male to female and choose the voice you want to use

Gender = "Female"# @param ['Male', 'Female']

female_voice="en-US-AriaNeural"# @param["en-US-AriaNeural",'zh-CN-XiaoxiaoNeural','zh-CN-XiaoyiNeural']

speed = 1  # @param {type: "number"}

translate_text_flag  = False

if len(text)>=600:

  long_sentence = True

else:

  long_sentence = False

# long_sentence = False # @param {type:"boolean"}

save_path = ''  # @param {type: "string"}

if len(save_path)==0:

  save_path=tts_file_name(text)

if Language == "English" :

  if Gender=="Male":

    voice_name="en-US-ChristopherNeural"

  if Gender=="Female":

    voice_name=female_voice

    # voice_name="en-US-AriaNeural"

if translate_text_flag:

  input_text=text

  # input_text=translate_text(text, Language)

  # print("Translateting")

else:

  input_text=text

if long_sentence==True and translate_text_flag==True:

  chunks_list=make_chunks(input_text,Language)

elif long_sentence==True and translate_text_flag==False:

  chunks_list=make_chunks(input_text,"English")

else:

  chunks_list=[input_text]

# print(chunks_list)

# edge_save_path=edge_free_tts(chunks_list,speed,voice_name,save_path)

# from IPython.display import clear_output

# clear_output()

# from IPython.display import Audio

# Audio(edge_save_path, autoplay=True)

from IPython.display import clear_output

from IPython.display import Audio

if not os.path.exists("./content/audio"):

    os.mkdir("./content/audio")

import uuid

def random_audio_name_generate():

  random_uuid = uuid.uuid4()

  audio_extension = ".mp3"

  random_audio_name = str(random_uuid)[:8] + audio_extension

  return random_audio_name

def talk(input_text):

  global translate_text_flag,Language,speed,voice_name

  if len(input_text)>=600:

    long_sentence = True

  else:

    long_sentence = False

  if long_sentence==True and translate_text_flag==True:

    chunks_list=make_chunks(input_text,Language)

  elif long_sentence==True and translate_text_flag==False:

    chunks_list=make_chunks(input_text,"English")

  else:

    chunks_list=[input_text]

  save_path="./content/audio/"+random_audio_name_generate()

  edge_save_path=edge_free_tts(chunks_list,speed,voice_name,save_path)

  return edge_save_path

edge_save_path=talk(text)

Audio(edge_save_path, autoplay=True)

主要用于将文本转换为语音。

1. calculate_rate_string(input_value) 函数:根据输入的值计算语音速度,并返回一个字符串。

2. make_chunks(input_text, language) 函数:将文本分割成多个部分,以便在语音中正确断句。

3. tts_file_name(text)` 函数:根据输入的文本生成一个唯一的音频文件名。

4. merge_audio_files(audio_paths, output_path) 函数:将多个音频文件合并为一个音频文件。

5. edge_free_tts(chunks_list, speed, voice_name, save_path) 函数:使用 Edge TTS 将文本转换为语音,并将生成的音频文件保存到指定的路径。

6. talk(input_text)函数:将输入的文本转换为语音,并返回生成的音频文件的路径。

7. edge_save_path=talk(text)` 调用 `talk() 函数,将文本转换为语音。

8. Audio(edge_save_path, autoplay=True)播放生成的音频文件。

这段代码的主要用途是将文本转换为语音,并可以自定义语音的速度和音色。

问题与解决方案:
  1. 问题分析: pip 和conda混用造成环境搭建等方面等问题。根据课程信息,集训人员应充分了解所使用的LLM模型,向量化模型和数据库的能力,针对模型和数据库的能力,对数据进行相应的处理,可以考虑换用模型,或者对数据进行进一步处理。
  2. 解决措施: 根据报错信息,仔细纠错。通过查询使用手册并在学习群和其他同学讨论来解决方案。
项目总结与展望:
  1. 项目评估:本项目完成了智能音乐平台语音识别与分析系统,完成了语音识别和分析功能,精准性和功能的丰富性有待提高。
  2. 未来方向:提高精准性和功能的丰富性,增加其他模态的输入和输出。
附件与参考资料

Nvidia官方培训网站Home | NVIDIA

https://blog.csdn.net/kunhe0512/article/details/140910139

  • 7
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值