docs/academic_recipe/asr_recipe.md
@@ -12,7 +12,7 @@ Then you can directly start the recipe as follows: ```sh conda activate funasr . ./run.sh --CUDA_VISIBLE_DEVICES="0,1" --gpu_num=2 bash run.sh --CUDA_VISIBLE_DEVICES "0,1" --gpu_num 2 ``` The training log files are saved in `${exp_dir}/exp/${model_dir}/log/train.log.*`, which can be viewed using the following command: funasr/runtime/deploy_tools/funasr-runtime-deploy-offline-cpu-en.sh
New file @@ -0,0 +1,1739 @@ #!/usr/bin/env bash scriptVersion="0.0.1" scriptDate="20231010" # Set color RED="\033[31;1m" GREEN="\033[32;1m" YELLOW="\033[33;1m" BLUE="\033[34;1m" CYAN="\033[36;1m" PLAIN="\033[0m" # Info messages DONE="${GREEN}[DONE]${PLAIN}" ERROR="${RED}[ERROR]${PLAIN}" WARNING="${YELLOW}[WARNING]${PLAIN}" # Font Format BOLD="\033[1m" UNDERLINE="\033[4m" # Current folder CUR_DIR=`pwd` SUDO_CMD="sudo" DEFAULT_DOCKER_OFFLINE_CPU_EN_LISTS_OSS="https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/docker_lists/docker_offline_cpu_en_lists" DEFAULT_DOCKER_OFFLINE_CPU_EN_LISTS_GIT="https://raw.githubusercontent.com/alibaba-damo-academy/FunASR/main/funasr/runtime/docs/docker_offline_cpu_en_lists" DEFAULT_DOCKER_IMAGE_LISTS=$DEFAULT_DOCKER_OFFLINE_CPU_EN_LISTS_OSS DEFAULT_FUNASR_DOCKER_URL="registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr" DEFAULT_FUNASR_RUNTIME_RESOURCES="funasr-runtime-resources" DEFAULT_FUNASR_LOCAL_WORKSPACE=${CUR_DIR}/${DEFAULT_FUNASR_RUNTIME_RESOURCES} DEFAULT_FUNASR_CONFIG_DIR="" DEFAULT_FUNASR_CONFIG_DIR_BAK="/var/funasr" DEFAULT_FUNASR_CONFIG_FILE="${DEFAULT_FUNASR_CONFIG_DIR}/config" DEFAULT_FUNASR_SERVER_CONFIG_FILE="${DEFAULT_FUNASR_CONFIG_DIR}/server_config" DEFAULT_FUNASR_PROGRESS_TXT="${DEFAULT_FUNASR_CONFIG_DIR}/progress.txt" DEFAULT_FUNASR_SERVER_LOG="${DEFAULT_FUNASR_CONFIG_DIR}/server_console.log" DEFAULT_FUNASR_WORKSPACE_DIR="/workspace/models" DEFAULT_DOCKER_PORT="10095" DEFAULT_PROGRESS_FILENAME="progress.txt" DEFAULT_SERVER_EXEC_NAME="funasr-wss-server" DEFAULT_DOCKER_EXEC_DIR="/workspace/FunASR/funasr/runtime/websocket/build/bin" DEFAULT_DOCKER_EXEC_PATH=${DEFAULT_DOCKER_EXEC_DIR}/${DEFAULT_SERVER_EXEC_NAME} DEFAULT_SAMPLES_NAME="funasr_samples" DEFAULT_SAMPLES_DIR="samples" DEFAULT_SAMPLES_URL="https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/sample/${DEFAULT_SAMPLES_NAME}.tar.gz" SAMPLE_CLIENTS=( \ "Python" \ "Linux_Cpp" \ ) DOCKER_IMAGES=() ASR_MODELS=() VAD_MODELS=() PUNC_MODELS=() # Handles the download progress bar asr_percent_int=0 vad_percent_int=0 punc_percent_int=0 asr_title="Downloading" asr_percent="0" asr_speed="0KB/s" asr_revision="" vad_title="Downloading" vad_percent="0" vad_speed="0KB/s" vad_revision="" punc_title="Downloading" punc_percent="0" punc_speed="0KB/s" punc_revision="" serverProgress(){ status_flag="STATUS:" stage=0 wait=0 server_status="" while true do if [ -f "$DEFAULT_FUNASR_PROGRESS_TXT" ]; then break else sleep 1 let wait=wait+1 if [ ${wait} -ge 6 ]; then break fi fi done if [ ! -f "$DEFAULT_FUNASR_PROGRESS_TXT" ]; then echo -e " ${RED}The note of progress does not exist.($DEFAULT_FUNASR_PROGRESS_TXT) ${PLAIN}" return 98 fi stage=1 while read line do if [ $stage -eq 1 ]; then result=$(echo $line | grep "STATUS:") if [ "$result" != "" ]; then stage=2 server_status=${line#*:} status=`expr $server_status + 0` if [ $status -eq 99 ]; then stage=99 fi continue fi elif [ $stage -eq 2 ]; then result=$(echo $line | grep "ASR") if [ "$result" != "" ]; then stage=3 continue fi elif [ $stage -eq 3 ]; then result=$(echo $line | grep "VAD") if [ "$result" != "" ]; then stage=4 continue fi result=$(echo $line | grep "title:") if [ "$result" != "" ]; then asr_title=${line#*:} continue fi result=$(echo $line | grep "percent:") if [ "$result" != "" ]; then asr_percent=${line#*:} continue fi result=$(echo $line | grep "speed:") if [ "$result" != "" ]; then asr_speed=${line#*:} continue fi result=$(echo $line | grep "revision:") if [ "$result" != "" ]; then asr_revision=${line#*:} continue fi elif [ $stage -eq 4 ]; then result=$(echo $line | grep "PUNC") if [ "$result" != "" ]; then stage=5 continue fi result=$(echo $line | grep "title:") if [ "$result" != "" ]; then vad_title=${line#*:} continue fi result=$(echo $line | grep "percent:") if [ "$result" != "" ]; then vad_percent=${line#*:} continue fi result=$(echo $line | grep "speed:") if [ "$result" != "" ]; then vad_speed=${line#*:} continue fi result=$(echo $line | grep "revision:") if [ "$result" != "" ]; then vad_revision=${line#*:} continue fi elif [ $stage -eq 5 ]; then result=$(echo $line | grep "DONE") if [ "$result" != "" ]; then # Done and break. stage=6 break fi result=$(echo $line | grep "title:") if [ "$result" != "" ]; then punc_title=${line#*:} continue fi result=$(echo $line | grep "percent:") if [ "$result" != "" ]; then punc_percent=${line#*:} continue fi result=$(echo $line | grep "speed:") if [ "$result" != "" ]; then punc_speed=${line#*:} continue fi result=$(echo $line | grep "revision:") if [ "$result" != "" ]; then punc_revision=${line#*:} continue fi elif [ $stage -eq 99 ]; then echo -e " ${RED}ERROR: $line${PLAIN}" fi done < $DEFAULT_FUNASR_PROGRESS_TXT if [ $stage -ne 99 ]; then drawProgress "ASR " $asr_title $asr_percent $asr_speed $asr_revision $asr_percent_int asr_percent_int=$? drawProgress "VAD " $vad_title $vad_percent $vad_speed $vad_revision $vad_percent_int vad_percent_int=$? drawProgress "PUNC" $punc_title $punc_percent $punc_speed $punc_revision $punc_percent_int punc_percent_int=$? fi return $stage } drawProgress(){ model=$1 title=$2 percent_str=$3 speed=$4 revision=$5 latest_percent=$6 progress=0 if [ ! -z "$percent_str" ]; then progress=`expr $percent_str + 0` latest_percent=`expr $latest_percent + 0` if [ $progress -ne 0 ] && [ $progress -lt $latest_percent ]; then progress=$latest_percent fi fi loading_flag="Loading" if [ "$title" = "$loading_flag" ]; then progress=100 fi i=0 str="" let max=progress/2 while [ $i -lt $max ] do let i++ str+='=' done let color=36 let index=max*2 if [ -z "$speed" ]; then printf "\r \e[0;${CYAN}[%s][%-11s][%-50s][%d%%][%s]\e[0m" "$model" "$title" "$str" "$$index" "$revision" else printf "\r \e[0;${CYAN}[%s][%-11s][%-50s][%3d%%][%8s][%s]\e[0m" "$model" "$title" "$str" "$index" "$speed" "$revision" fi printf "\n" return $progress } menuSelection(){ local menu menu=($(echo "$@")) result=1 show_no=1 menu_no=0 len=${#menu[@]} while true do echo -e " ${BOLD}${show_no})${PLAIN} ${menu[menu_no]}" let show_no++ let menu_no++ if [ $menu_no -ge $len ]; then break fi done while true do echo -e " Enter your choice, default(${CYAN}1${PLAIN}): \c" read result if [ -z "$result" ]; then result=1 fi expr $result + 0 &>/dev/null if [ $? -eq 0 ]; then if [ $result -ge 1 ] && [ $result -le $len ]; then break else echo -e " ${RED}Input error, please input correct number!${PLAIN}" fi else echo -e " ${RED}Input error, please input correct number!${PLAIN}" fi done return $result } full_path="" relativePathToFullPath(){ relativePath=$1 firstChar=${relativePath: 0: 1} if [[ "$firstChar" == "" ]]; then full_path=$relativePath elif [[ "$firstChar" == "/" ]]; then full_path=$relativePath fi tmpPath1=`dirname $relativePath` tmpFullpath1=`cd $tmpPath1 && pwd` tmpPath2=`basename $relativePath` full_path=${tmpFullpath1}/${tmpPath2} } initConfiguration(){ if [ -z "$DEFAULT_FUNASR_CONFIG_DIR" ];then DEFAULT_FUNASR_CONFIG_DIR="$HOME" if [ -z "$DEFAULT_FUNASR_CONFIG_DIR" ];then $DEFAULT_FUNASR_CONFIG_DIR=$(echo ~/) if [ -z "$DEFAULT_FUNASR_CONFIG_DIR" ];then $DEFAULT_FUNASR_CONFIG_DIR=$DEFAULT_FUNASR_CONFIG_DIR_BAK fi fi DEFAULT_FUNASR_CONFIG_DIR=${DEFAULT_FUNASR_CONFIG_DIR}/.funasr fi if [ ! -z "$DEFAULT_FUNASR_CONFIG_DIR" ]; then $SUDO_CMD mkdir -p $DEFAULT_FUNASR_CONFIG_DIR else echo -e " ${RED}DEFAULT_FUNASR_CONFIG_DIR is empty!${PLAIN}" exit 1 fi if [ ! -d "$DEFAULT_FUNASR_CONFIG_DIR" ]; then echo -e " ${RED}${DEFAULT_FUNASR_CONFIG_DIR} does not exist!${PLAIN}" exit 2 fi DEFAULT_FUNASR_CONFIG_FILE="${DEFAULT_FUNASR_CONFIG_DIR}/config" DEFAULT_FUNASR_SERVER_CONFIG_FILE="${DEFAULT_FUNASR_CONFIG_DIR}/server_config" DEFAULT_FUNASR_PROGRESS_TXT="${DEFAULT_FUNASR_CONFIG_DIR}/progress.txt" DEFAULT_FUNASR_SERVER_LOG="${DEFAULT_FUNASR_CONFIG_DIR}/server_console.log" if [ ! -f $DEFAULT_FUNASR_CONFIG_FILE ]; then $SUDO_CMD touch $DEFAULT_FUNASR_CONFIG_FILE fi if [ ! -f $DEFAULT_FUNASR_SERVER_CONFIG_FILE ]; then $SUDO_CMD touch $DEFAULT_FUNASR_SERVER_CONFIG_FILE fi } initParameters(){ # Init workspace in local by new parameters. PARAMS_FUNASR_SAMPLES_LOCAL_PATH=${PARAMS_FUNASR_LOCAL_WORKSPACE}/${DEFAULT_SAMPLES_NAME}.tar.gz PARAMS_FUNASR_SAMPLES_LOCAL_DIR=${PARAMS_FUNASR_LOCAL_WORKSPACE}/${DEFAULT_SAMPLES_DIR} PARAMS_FUNASR_LOCAL_MODELS_DIR="${PARAMS_FUNASR_LOCAL_WORKSPACE}/models" if [ ! -z "$PARAMS_FUNASR_LOCAL_WORKSPACE" ]; then mkdir -p $PARAMS_FUNASR_LOCAL_WORKSPACE fi if [ ! -z "$PARAMS_FUNASR_LOCAL_MODELS_DIR" ]; then mkdir -p $PARAMS_FUNASR_LOCAL_MODELS_DIR fi } # Parse the parameters from the docker list file. docker_info_cur_key="" docker_info_cur_val="" findTypeOfDockerInfo(){ line=$1 result=$(echo $line | grep ":") if [ "$result" != "" ]; then docker_info_cur_key=$result docker_info_cur_val="" else docker_info_cur_val=$(echo $line) fi } # Get a list of docker images. readDockerInfoFromUrl(){ while true do list_url=$DEFAULT_DOCKER_IMAGE_LISTS content=$(curl --connect-timeout 10 -m 10 -s $list_url) if [ ! -z "$content" ]; then break else echo -e " ${RED}Unable to get docker image list due to network issues, try again.${PLAIN}" # switch sources of docker image lists if [ "$list_url" = "$DEFAULT_DOCKER_OFFLINE_CPU_EN_LISTS_OSS" ]; then DEFAULT_DOCKER_IMAGE_LISTS=$DEFAULT_DOCKER_OFFLINE_CPU_EN_LISTS_GIT else DEFAULT_DOCKER_IMAGE_LISTS=$DEFAULT_DOCKER_OFFLINE_CPU_EN_LISTS_OSS fi fi done array=($(echo "$content")) len=${#array[@]} for i in ${array[@]} do findTypeOfDockerInfo $i if [ "$docker_info_cur_key" = "DOCKER:" ]; then if [ ! -z "$docker_info_cur_val" ]; then docker_name=${DEFAULT_FUNASR_DOCKER_URL}:${docker_info_cur_val} DOCKER_IMAGES[${#DOCKER_IMAGES[*]}]=$docker_name fi elif [ "$docker_info_cur_key" = "DEFAULT_ASR_MODEL:" ]; then if [ ! -z "$docker_info_cur_val" ]; then ASR_MODELS[${#ASR_MODELS[*]}]=$docker_info_cur_val fi elif [ "$docker_info_cur_key" = "DEFAULT_VAD_MODEL:" ]; then if [ ! -z "$docker_info_cur_val" ]; then VAD_MODELS[${#VAD_MODELS[*]}]=$docker_info_cur_val fi elif [ "$docker_info_cur_key" = "DEFAULT_PUNC_MODEL:" ]; then if [ ! -z "$docker_info_cur_val" ]; then PUNC_MODELS[${#PUNC_MODELS[*]}]=$docker_info_cur_val fi fi done echo -e " $DONE" } # Make sure root user. rootNess(){ echo -e "${UNDERLINE}${BOLD}[0/6]${PLAIN}" echo -e " ${YELLOW}Please check root access.${PLAIN}" echo -e " ${WARNING} MUST RUN AS ${RED}ROOT${PLAIN} USER!" if [[ $EUID -ne 0 ]]; then echo -e " ${ERROR} MUST RUN AS ${RED}ROOT${PLAIN} USER!" fi check_sudo=$(which sudo | wc -l) if [ $check_sudo -eq 0 ]; then SUDO_CMD="" fi cd $CUR_DIR echo } # Get a list of docker images and select them. selectDockerImages(){ echo -e "${UNDERLINE}${BOLD}[1/6]${PLAIN}" echo -e " ${YELLOW}Getting the list of docker images, please wait a few seconds.${PLAIN}" readDockerInfoFromUrl echo the_latest_docker_image=$PARAMS_DOCKER_IMAGE echo -e " ${YELLOW}Please choose the Docker image.${PLAIN}" menuSelection ${DOCKER_IMAGES[*]} result=$? index=`expr ${result} - 1` PARAMS_DOCKER_IMAGE=${DOCKER_IMAGES[${index}]} echo -e " ${UNDERLINE}You have chosen the Docker image:${PLAIN} ${GREEN}${PARAMS_DOCKER_IMAGE}${PLAIN}" if [ -z "$the_latest_docker_image" ] && [ -z "$PARAMS_FUNASR_DOCKER_ID" ]; then result=0 else # 0: DOCKER is not running # 60: DOCKER_ID is empty # 61: DOCKER_IMAGE is empty # 62: DOCKER is running # 63: DOCKER_ID and DOCKER_IMAGE are empty checkDockerIdExist "install" result=$? result=`expr ${result} + 0` if [ $result -eq 60 ]; then result=0 elif [ $result -eq 61 ]; then echo echo -e " ${RED}Please run (${PLAIN}${GREEN}${SUDO_CMD} bash funasr-runtime-deploy-offline-cpu-en.sh install${PLAIN}${RED}) to install Docker first.${PLAIN}" elif [ $result -eq 62 ]; then echo echo -e " ${RED}Docker: ${PARAMS_DOCKER_IMAGE} ${PARAMS_FUNASR_DOCKER_ID} has been launched, please run (${PLAIN}${GREEN}${SUDO_CMD} bash funasr-runtime-deploy-offline-cpu-en.sh remove${PLAIN}${RED}) to remove Docker first ant then install.${PLAIN}" elif [ $result -eq 63 ]; then result=0 fi fi echo } # Get a list of models and select them. selectModels(){ echo -e "${UNDERLINE}${BOLD}[2/6]${PLAIN}" echo -e " ${YELLOW}Get a list of selectable models.${PLAIN}" echo selectAsrModels selectVadModels selectPuncModels echo } selectAsrModels(){ echo -e " ${YELLOW}Please choose the ASR model.${PLAIN}" menuSelection ${ASR_MODELS[*]} result=$? index=`expr ${result} - 1` PARAMS_ASR_ID=${ASR_MODELS[${index}]} echo -e " ${UNDERLINE}You have chosen the ASR model:${PLAIN} ${GREEN}${PARAMS_ASR_ID}${PLAIN}" echo } selectVadModels(){ echo -e " ${YELLOW}Please choose the VAD model.${PLAIN}" menuSelection ${VAD_MODELS[*]} result=$? index=`expr ${result} - 1` PARAMS_VAD_ID=${VAD_MODELS[${index}]} echo -e " ${UNDERLINE}You have chosen the VAD model:${PLAIN} ${GREEN}${PARAMS_VAD_ID}${PLAIN}" echo } selectPuncModels(){ echo -e " ${YELLOW}Please choose the PUNC model.${PLAIN}" menuSelection ${PUNC_MODELS[*]} result=$? index=`expr ${result} - 1` PARAMS_PUNC_ID=${PUNC_MODELS[${index}]} echo -e " ${UNDERLINE}You have chosen the PUNC model:${PLAIN} ${GREEN}${PARAMS_PUNC_ID}${PLAIN}" echo } # Configure FunASR server host port setting. setupHostPort(){ echo -e "${UNDERLINE}${BOLD}[3/6]${PLAIN}" params_host_port=`sed '/^PARAMS_HOST_PORT=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ -z "$params_host_port" ]; then PARAMS_HOST_PORT="10095" else PARAMS_HOST_PORT=$params_host_port fi while true do echo -e " ${YELLOW}Please input the opened port in the host used for FunASR server.${PLAIN}" echo -e " Setting the opened host port [1-65535], default(${CYAN}${PARAMS_HOST_PORT}${PLAIN}): \c" read PARAMS_HOST_PORT if [ -z "$PARAMS_HOST_PORT" ]; then params_host_port=`sed '/^PARAMS_HOST_PORT=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ -z "$params_host_port" ]; then PARAMS_HOST_PORT="10095" else PARAMS_HOST_PORT=$params_host_port fi fi expr $PARAMS_HOST_PORT + 0 &>/dev/null if [ $? -eq 0 ]; then if [ $PARAMS_HOST_PORT -ge 1 ] && [ $PARAMS_HOST_PORT -le 65535 ]; then echo -e " ${UNDERLINE}The port of the host is${PLAIN} ${GREEN}${PARAMS_HOST_PORT}${PLAIN}" echo -e " ${UNDERLINE}The port in Docker for FunASR server is${PLAIN} ${GREEN}${PARAMS_DOCKER_PORT}${PLAIN}" break else echo -e " ${RED}Input error, please input correct number!${PLAIN}" fi else echo -e " ${RED}Input error, please input correct number!${PLAIN}" fi done echo } complementParameters(){ # parameters about ASR model if [ ! -z "$PARAMS_ASR_ID" ]; then PARAMS_DOCKER_ASR_PATH=${PARAMS_DOWNLOAD_MODEL_DIR}/${PARAMS_ASR_ID} PARAMS_DOCKER_ASR_DIR=$(dirname "$PARAMS_DOCKER_ASR_PATH") PARAMS_LOCAL_ASR_PATH=${PARAMS_FUNASR_LOCAL_MODELS_DIR}/${PARAMS_ASR_ID} PARAMS_LOCAL_ASR_DIR=$(dirname "$PARAMS_LOCAL_ASR_PATH") fi # parameters about VAD model if [ ! -z "$PARAMS_VAD_ID" ]; then PARAMS_DOCKER_VAD_PATH=${PARAMS_DOWNLOAD_MODEL_DIR}/${PARAMS_VAD_ID} PARAMS_DOCKER_VAD_DIR=$(dirname "$PARAMS_DOCKER_VAD_PATH") PARAMS_LOCAL_VAD_PATH=${PARAMS_FUNASR_LOCAL_MODELS_DIR}/${PARAMS_VAD_ID} PARAMS_LOCAL_VAD_DIR=$(dirname "$PARAMS_LOCAL_VAD_PATH") fi # parameters about PUNC model if [ ! -z "$PARAMS_PUNC_ID" ]; then PARAMS_DOCKER_PUNC_PATH=${PARAMS_DOWNLOAD_MODEL_DIR}/${PARAMS_PUNC_ID} PARAMS_DOCKER_PUNC_DIR=$(dirname "${PARAMS_DOCKER_PUNC_PATH}") PARAMS_LOCAL_PUNC_PATH=${PARAMS_FUNASR_LOCAL_MODELS_DIR}/${PARAMS_PUNC_ID} PARAMS_LOCAL_PUNC_DIR=$(dirname "${PARAMS_LOCAL_PUNC_PATH}") fi # parameters about thread_num params_decoder_thread_num=`sed '/^PARAMS_DECODER_THREAD_NUM=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ -z "$params_decoder_thread_num" ]; then PARAMS_DECODER_THREAD_NUM=$CPUNUM else PARAMS_DECODER_THREAD_NUM=$params_decoder_thread_num fi multiple_io=4 PARAMS_DECODER_THREAD_NUM=`expr ${PARAMS_DECODER_THREAD_NUM} + 0` PARAMS_IO_THREAD_NUM=`expr ${PARAMS_DECODER_THREAD_NUM} / ${multiple_io}` if [ $PARAMS_IO_THREAD_NUM -eq 0 ]; then PARAMS_IO_THREAD_NUM=1 fi } paramsFromDefault(){ initConfiguration echo -e " ${YELLOW}Load parameters from${PLAIN} ${GREEN}${DEFAULT_FUNASR_CONFIG_FILE}${PLAIN}" echo funasr_local_workspace=`sed '/^PARAMS_FUNASR_LOCAL_WORKSPACE=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$funasr_local_workspace" ]; then PARAMS_FUNASR_LOCAL_WORKSPACE=$funasr_local_workspace fi funasr_samples_local_dir=`sed '/^PARAMS_FUNASR_SAMPLES_LOCAL_DIR=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$funasr_samples_local_dir" ]; then PARAMS_FUNASR_SAMPLES_LOCAL_DIR=$funasr_samples_local_dir fi funasr_samples_local_path=`sed '/^PARAMS_FUNASR_SAMPLES_LOCAL_PATH=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$funasr_samples_local_path" ]; then PARAMS_FUNASR_SAMPLES_LOCAL_PATH=$funasr_samples_local_path fi funasr_local_models_dir=`sed '/^PARAMS_FUNASR_LOCAL_MODELS_DIR=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$funasr_local_models_dir" ]; then PARAMS_FUNASR_LOCAL_MODELS_DIR=$funasr_local_models_dir fi docker_image=`sed '/^PARAMS_DOCKER_IMAGE=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$docker_image" ]; then PARAMS_DOCKER_IMAGE=$docker_image fi download_model_dir=`sed '/^PARAMS_DOWNLOAD_MODEL_DIR=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$download_model_dir" ]; then PARAMS_DOWNLOAD_MODEL_DIR=$download_model_dir fi PARAMS_LOCAL_ASR_PATH=`sed '/^PARAMS_LOCAL_ASR_PATH=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$local_asr_path" ]; then PARAMS_LOCAL_ASR_PATH=$local_asr_path fi docker_asr_path=`sed '/^PARAMS_DOCKER_ASR_PATH=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$docker_asr_path" ]; then PARAMS_DOCKER_ASR_PATH=$docker_asr_path fi asr_id=`sed '/^PARAMS_ASR_ID=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$asr_id" ]; then PARAMS_ASR_ID=$asr_id fi local_vad_path=`sed '/^PARAMS_LOCAL_VAD_PATH=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$local_vad_path" ]; then PARAMS_LOCAL_VAD_PATH=$local_vad_path fi docker_vad_path=`sed '/^PARAMS_DOCKER_VAD_PATH=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$docker_vad_path" ]; then PARAMS_DOCKER_VAD_PATH=$docker_vad_path fi vad_id=`sed '/^PARAMS_VAD_ID=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$vad_id" ]; then PARAMS_VAD_ID=$vad_id fi local_punc_path=`sed '/^PARAMS_LOCAL_PUNC_PATH=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$local_punc_path" ]; then PARAMS_LOCAL_PUNC_PATH=$local_punc_path fi docker_punc_path=`sed '/^PARAMS_DOCKER_PUNC_PATH=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$docker_punc_path" ]; then PARAMS_DOCKER_PUNC_PATH=$docker_punc_path fi punc_id=`sed '/^PARAMS_PUNC_ID=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$punc_id" ]; then PARAMS_PUNC_ID=$punc_id fi docker_exec_path=`sed '/^PARAMS_DOCKER_EXEC_PATH=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$docker_exec_path" ]; then PARAMS_DOCKER_EXEC_PATH=$docker_exec_path fi host_port=`sed '/^PARAMS_HOST_PORT=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$host_port" ]; then PARAMS_HOST_PORT=$host_port fi docker_port=`sed '/^PARAMS_DOCKER_PORT=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$docker_port" ]; then PARAMS_DOCKER_PORT=$docker_port fi decode_thread_num=`sed '/^PARAMS_DECODER_THREAD_NUM=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$decode_thread_num" ]; then PARAMS_DECODER_THREAD_NUM=$decode_thread_num fi io_thread_num=`sed '/^PARAMS_IO_THREAD_NUM=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$io_thread_num" ]; then PARAMS_IO_THREAD_NUM=$io_thread_num fi ssl_flag=`sed '/^PARAMS_SSL_FLAG=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$ssl_flag" ]; then PARAMS_SSL_FLAG=$ssl_flag fi docker_id=`sed '/^PARAMS_FUNASR_DOCKER_ID=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ ! -z "$docker_id" ]; then PARAMS_FUNASR_DOCKER_ID=$docker_id fi } saveParams(){ echo "$i" > $DEFAULT_FUNASR_CONFIG_FILE echo -e " ${GREEN}Parameters are stored in the file ${DEFAULT_FUNASR_CONFIG_FILE}${PLAIN}" echo "PARAMS_DOCKER_IMAGE=${PARAMS_DOCKER_IMAGE}" > $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_FUNASR_LOCAL_WORKSPACE=${PARAMS_FUNASR_LOCAL_WORKSPACE}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_FUNASR_SAMPLES_LOCAL_DIR=${PARAMS_FUNASR_SAMPLES_LOCAL_DIR}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_FUNASR_SAMPLES_LOCAL_PATH=${PARAMS_FUNASR_SAMPLES_LOCAL_PATH}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_FUNASR_LOCAL_MODELS_DIR=${PARAMS_FUNASR_LOCAL_MODELS_DIR}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_DOWNLOAD_MODEL_DIR=${PARAMS_DOWNLOAD_MODEL_DIR}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_DOCKER_EXEC_PATH=${PARAMS_DOCKER_EXEC_PATH}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_DOCKER_EXEC_DIR=${PARAMS_DOCKER_EXEC_DIR}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_LOCAL_ASR_PATH=${PARAMS_LOCAL_ASR_PATH}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_LOCAL_ASR_DIR=${PARAMS_LOCAL_ASR_DIR}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_DOCKER_ASR_PATH=${PARAMS_DOCKER_ASR_PATH}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_DOCKER_ASR_DIR=${PARAMS_DOCKER_ASR_DIR}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_ASR_ID=${PARAMS_ASR_ID}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_LOCAL_PUNC_PATH=${PARAMS_LOCAL_PUNC_PATH}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_LOCAL_PUNC_DIR=${PARAMS_LOCAL_PUNC_DIR}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_DOCKER_PUNC_PATH=${PARAMS_DOCKER_PUNC_PATH}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_DOCKER_PUNC_DIR=${PARAMS_DOCKER_PUNC_DIR}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_PUNC_ID=${PARAMS_PUNC_ID}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_LOCAL_VAD_PATH=${PARAMS_LOCAL_VAD_PATH}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_LOCAL_VAD_DIR=${PARAMS_LOCAL_VAD_DIR}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_DOCKER_VAD_PATH=${PARAMS_DOCKER_VAD_PATH}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_DOCKER_VAD_DIR=${PARAMS_DOCKER_VAD_DIR}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_VAD_ID=${PARAMS_VAD_ID}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_HOST_PORT=${PARAMS_HOST_PORT}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_DOCKER_PORT=${PARAMS_DOCKER_PORT}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_DECODER_THREAD_NUM=${PARAMS_DECODER_THREAD_NUM}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_IO_THREAD_NUM=${PARAMS_IO_THREAD_NUM}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_SSL_FLAG=${PARAMS_SSL_FLAG}" >> $DEFAULT_FUNASR_CONFIG_FILE echo "PARAMS_FUNASR_DOCKER_ID=${PARAMS_FUNASR_DOCKER_ID}" >> $DEFAULT_FUNASR_CONFIG_FILE serverConfigGeneration echo "${daemon_server_config}" > $DEFAULT_FUNASR_SERVER_CONFIG_FILE } showAllParams(){ echo -e "${UNDERLINE}${BOLD}[4/6]${PLAIN}" echo -e " ${YELLOW}Show parameters of FunASR server setting and confirm to run ...${PLAIN}" echo only_show_flag=$1 if [ ! -z "$PARAMS_DOCKER_IMAGE" ]; then echo -e " The current Docker image is : ${GREEN}${PARAMS_DOCKER_IMAGE}${PLAIN}" fi if [ ! -z "$PARAMS_FUNASR_LOCAL_WORKSPACE" ]; then echo -e " The local workspace path is : ${GREEN}${PARAMS_FUNASR_LOCAL_WORKSPACE}${PLAIN}" fi if [ ! -z "$PARAMS_DOWNLOAD_MODEL_DIR" ]; then echo -e " The model will be automatically downloaded in Docker : ${GREEN}${PARAMS_DOWNLOAD_MODEL_DIR}${PLAIN}" fi echo if [ ! -z "$PARAMS_ASR_ID" ]; then echo -e " The ASR model_id used : ${GREEN}${PARAMS_ASR_ID}${PLAIN}" fi if [ ! -z "$PARAMS_LOCAL_ASR_PATH" ]; then echo -e " The path to the local ASR model directory for the load : ${GREEN}${PARAMS_LOCAL_ASR_PATH}${PLAIN}" fi echo -e " The ASR model directory corresponds to the directory in Docker : ${GREEN}${PARAMS_DOCKER_ASR_PATH}${PLAIN}" if [ ! -z "$PARAMS_VAD_ID" ]; then echo -e " The VAD model_id used : ${GREEN}${PARAMS_VAD_ID}${PLAIN}" fi if [ ! -z "$PARAMS_LOCAL_VAD_PATH" ]; then echo -e " The path to the local VAD model directory for the load : ${GREEN}${PARAMS_LOCAL_VAD_PATH}${PLAIN}" fi echo -e " The VAD model directory corresponds to the directory in Docker : ${GREEN}${PARAMS_DOCKER_VAD_PATH}${PLAIN}" if [ ! -z "$PARAMS_PUNC_ID" ]; then echo -e " The PUNC model_id used : ${GREEN}${PARAMS_PUNC_ID}${PLAIN}" fi if [ ! -z "$PARAMS_LOCAL_PUNC_PATH" ]; then echo -e " The path to the local PUNC model directory for the load : ${GREEN}${PARAMS_LOCAL_PUNC_PATH}${PLAIN}" fi echo -e " The PUNC model directory corresponds to the directory in Docker: ${GREEN}${PARAMS_DOCKER_PUNC_PATH}${PLAIN}" echo echo -e " The path in the docker of the FunASR service executor : ${GREEN}${PARAMS_DOCKER_EXEC_PATH}${PLAIN}" echo -e " Set the host port used for use by the FunASR service : ${GREEN}${PARAMS_HOST_PORT}${PLAIN}" echo -e " Set the docker port used by the FunASR service : ${GREEN}${PARAMS_DOCKER_PORT}${PLAIN}" echo -e " Set the number of threads used for decoding the FunASR service : ${GREEN}${PARAMS_DECODER_THREAD_NUM}${PLAIN}" echo -e " Set the number of threads used for IO the FunASR service : ${GREEN}${PARAMS_IO_THREAD_NUM}${PLAIN}" echo if [ ! -z "$PARAMS_FUNASR_SAMPLES_LOCAL_DIR" ]; then echo -e " Sample code will be store in local : ${GREEN}${PARAMS_FUNASR_SAMPLES_LOCAL_DIR}${PLAIN}" fi if [ ! -z "$PARAMS_SSL_FLAG" ]; then echo -e " The flag for the use of SSL : ${GREEN}${PARAMS_SSL_FLAG}${PLAIN}" fi if [ "$only_show_flag" = "only_show" ] && [ ! -z "$PARAMS_FUNASR_DOCKER_ID" ]; then echo -e " The docker ID that already exists is : ${GREEN}${PARAMS_FUNASR_DOCKER_ID}${PLAIN}" fi echo if [ "$only_show_flag" = "only_show" ]; then return 0 fi while true do params_confirm="y" echo -e " ${YELLOW}Please input [Y/n] to confirm the parameters.${PLAIN}" echo -e " [y] Verify that these parameters are correct and that the service will run." echo -e " [n] The parameters set are incorrect, it will be rolled out, please rerun." echo -e " read confirmation[${CYAN}Y${PLAIN}/n]: \c" read params_confirm if [ -z "$params_confirm" ]; then params_confirm="y" fi YES="Y" yes="y" NO="N" no="n" echo if [ "$params_confirm" = "$YES" ] || [ "$params_confirm" = "$yes" ]; then echo -e " ${GREEN}Will run FunASR server later ...${PLAIN}" break elif [ "$params_confirm" = "$NO" ] || [ "$params_confirm" = "$no" ]; then echo -e " ${RED}The parameters set are incorrect, please rerun ...${PLAIN}" exit 1 else echo "again ..." fi done saveParams echo sleep 1 } # Install docker installFunasrDocker(){ echo -e "${UNDERLINE}${BOLD}[5/6]${PLAIN}" if [ $DOCKERINFOLEN -gt 30 ]; then echo -e " ${YELLOW}Docker has installed.${PLAIN}" else lowercase_osid=$(echo ${OSID} | tr '[A-Z]' '[a-z]') echo -e " ${YELLOW}Start install docker for ${lowercase_osid} ${PLAIN}" DOCKER_INSTALL_CMD="curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun" DOCKER_INSTALL_RUN_CMD="" case "$lowercase_osid" in ubuntu) DOCKER_INSTALL_CMD="curl -fsSL https://test.docker.com -o test-docker.sh" DOCKER_INSTALL_RUN_CMD="${SUDO_CMD} sh test-docker.sh" ;; centos) DOCKER_INSTALL_CMD="curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun" ;; debian) DOCKER_INSTALL_CMD="curl -fsSL https://get.docker.com -o get-docker.sh" DOCKER_INSTALL_RUN_CMD="${SUDO_CMD} sh get-docker.sh" ;; \"alios\") DOCKER_INSTALL_CMD="curl -fsSL https://get.docker.com -o get-docker.sh" DOCKER_INSTALL_RUN_CMD="${SUDO_CMD} sh get-docker.sh" ;; \"alinux\") DOCKER_INSTALL_CMD="${SUDO_CMD} yum -y install dnf" DOCKER_INSTALL_RUN_CMD="${SUDO_CMD} dnf -y install docker" ;; *) echo -e " ${RED}$lowercase_osid is not supported.${PLAIN}" ;; esac echo -e " Get docker installer: ${GREEN}${DOCKER_INSTALL_CMD}${PLAIN}" echo -e " Get docker run: ${GREEN}${DOCKER_INSTALL_RUN_CMD}${PLAIN}" $DOCKER_INSTALL_CMD if [ ! -z "$DOCKER_INSTALL_RUN_CMD" ]; then $DOCKER_INSTALL_RUN_CMD fi $SUDO_CMD systemctl start docker DOCKERINFO=$(${SUDO_CMD} docker info | wc -l) DOCKERINFOLEN=`expr ${DOCKERINFO} + 0` if [ $DOCKERINFOLEN -gt 30 ]; then echo -e " ${GREEN}Docker install success, start docker server.${PLAIN}" $SUDO_CMD systemctl start docker else echo -e " ${RED}Docker install failed!${PLAIN}" exit 1 fi fi echo sleep 1 # Download docker image echo -e " ${YELLOW}Pull docker image(${PARAMS_DOCKER_IMAGE})...${PLAIN}" ${SUDO_CMD} docker pull $PARAMS_DOCKER_IMAGE echo sleep 1 } dockerRun(){ echo -e "${UNDERLINE}${BOLD}[6/6]${PLAIN}" echo -e " ${YELLOW}Construct command and run docker ...${PLAIN}" start_flag=$1 if [ "$start_flag" = "install" ]; then run_cmd="${SUDO_CMD} docker run" port_map=" -p ${PARAMS_HOST_PORT}:${PARAMS_DOCKER_PORT}" env_params=" --privileged=true" dir_map_params=" -v ${DEFAULT_FUNASR_CONFIG_DIR}:/workspace/.config -v ${PARAMS_FUNASR_LOCAL_MODELS_DIR}:${PARAMS_DOWNLOAD_MODEL_DIR}" serverConfigGeneration env_params=" ${env_params} --env DAEMON_SERVER_CONFIG=${daemon_server_config}" run_cmd="${run_cmd}${port_map}${dir_map_params}${env_params}" run_cmd="${run_cmd} -it -d ${PARAMS_DOCKER_IMAGE}" else # 0: DOCKER is not running # 60: DOCKER_ID is empty # 61: DOCKER_IMAGE is empty # 62: DOCKER is running checkDockerIdExist $start_flag result=$? result=`expr ${result} + 0` if [ $result -eq 60 ]; then echo echo -e " ${RED}Please run (${PLAIN}${GREEN}${SUDO_CMD} bash funasr-runtime-deploy-offline-cpu-en.sh install${PLAIN}${RED}) to install Docker first.${PLAIN}" return $result elif [ $result -eq 61 ]; then echo echo -e " ${RED}Please run (${PLAIN}${GREEN}${SUDO_CMD} bash funasr-runtime-deploy-offline-cpu-en.sh install${PLAIN}${RED}) to install Docker first.${PLAIN}" return $result elif [ $result -eq 62 ]; then echo echo -e " ${RED}Docker: ${PARAMS_DOCKER_IMAGE} ${PARAMS_FUNASR_DOCKER_ID} has been launched, please run (${PLAIN}${GREEN}${SUDO_CMD} bash funasr-runtime-deploy-offline-cpu-en.sh stop${PLAIN}${RED}) to stop Docker first.${PLAIN}" return $result fi run_cmd="${SUDO_CMD} docker restart ${PARAMS_FUNASR_DOCKER_ID}" fi rm -f ${DEFAULT_FUNASR_PROGRESS_TXT} rm -f ${DEFAULT_FUNASR_SERVER_LOG} $run_cmd echo echo -e " ${YELLOW}Loading models:${PLAIN}" getDockerId saveParams # Hide the cursor, start draw progress. printf "\e[?25l" while true do serverProgress result=$? stage=`expr ${result} + 0` if [ ${stage} -eq 0 ]; then break elif [ ${stage} -gt 0 ] && [ ${stage} -lt 6 ]; then sleep 0.1 # clear 3 lines printf "\033[3A" elif [ ${stage} -eq 6 ]; then break elif [ ${stage} -eq 98 ]; then return 98 else echo -e " ${RED}Starting FunASR server failed.${PLAIN}" echo # Display the cursor printf "\e[?25h" return 99 fi done # Display the cursor printf "\e[?25h" echo -e " ${GREEN}The service has been started.${PLAIN}" echo deploySamples echo -e " ${BOLD}The sample code is already stored in the ${PLAIN}(${GREEN}${PARAMS_FUNASR_SAMPLES_LOCAL_DIR}${PLAIN}) ." echo -e " ${BOLD}If you want to see an example of how to use the client, you can run ${PLAIN}${GREEN}${SUDO_CMD} bash funasr-runtime-deploy-offline-cpu-en.sh client${PLAIN} ." echo } daemon_server_config="" serverConfigGeneration(){ # params about models if [ ! -z "$PARAMS_ASR_ID" ]; then asr_params="\"--model-dir\":\"${PARAMS_ASR_ID}\"" else if [ ! -z "$PARAMS_LOCAL_ASR_PATH" ]; then dir_map_params="${dir_map_params} -v ${PARAMS_LOCAL_ASR_PATH}:${PARAMS_DOCKER_ASR_PATH}" fi asr_params="\"--model-dir\":\"${PARAMS_DOCKER_ASR_PATH}\"" fi if [ ! -z "$PARAMS_VAD_ID" ]; then vad_params="\"--vad-dir\":\"${PARAMS_VAD_ID}\"" else if [ ! -z "$PARAMS_LOCAL_VAD_PATH" ]; then dir_map_params="${dir_map_params} -v ${PARAMS_LOCAL_VAD_PATH}:${PARAMS_DOCKER_VAD_PATH}" fi vad_params="\"--vad-dir\":\"${PARAMS_DOCKER_VAD_PATH}\"" fi if [ ! -z "$PARAMS_PUNC_ID" ]; then punc_params="\"--punc-dir\":\"${PARAMS_PUNC_ID}\"" else if [ ! -z "$PARAMS_LOCAL_PUNC_PATH" ]; then dir_map_params="${dir_map_params} -v ${PARAMS_LOCAL_VAD_PATH}:${PARAMS_DOCKER_VAD_PATH}" fi punc_params="\"--punc-dir\":\"${PARAMS_DOCKER_PUNC_PATH}\"" fi download_params="\"--download-model-dir\":\"${PARAMS_DOWNLOAD_MODEL_DIR}\"" model_params="${asr_params},${vad_params},${punc_params},${download_params}" # params about thread_num decoder_params="\"--decoder-thread-num\":\"${PARAMS_DECODER_THREAD_NUM}\"" io_params="\"--io-thread-num\":\"${PARAMS_IO_THREAD_NUM}\"" thread_params=${decoder_params},${io_params} # params about port and ssl port_params="\"--port\":\"${PARAMS_DOCKER_PORT}\"" if [ $PARAMS_SSL_FLAG -eq 0 ]; then crt_path="\"--certfile\":\"\"" key_path="\"--keyfile\":\"\"" else crt_path="\"--certfile\":\"/workspace/FunASR/funasr/runtime/ssl_key/server.crt\"" key_path="\"--keyfile\":\"/workspace/FunASR/funasr/runtime/ssl_key/server.key\"" fi exec_params="\"exec\":\"${PARAMS_DOCKER_EXEC_PATH}\"" daemon_server_config="{\"server\":[{${exec_params},${model_params},${thread_params},${port_params},${crt_path},${key_path}}]}" } installPythonDependencyForPython(){ echo -e "${YELLOW}Install Python dependent environments ...${PLAIN}" echo -e " Export dependency of Cpp sample." pre_cmd="export LD_LIBRARY_PATH=${PARAMS_FUNASR_SAMPLES_LOCAL_DIR}/cpp/libs:\$LD_LIBRARY_PATH" $pre_cmd echo echo -e " Install requirements of Python sample." pre_cmd="pip3 install click>=8.0.4" $pre_cmd echo pre_cmd="pip3 install -r ${PARAMS_FUNASR_SAMPLES_LOCAL_DIR}/python/requirements_client.txt" echo -e " Run ${BLUE}${pre_cmd}${PLAIN}" $pre_cmd echo lowercase_osid=$(echo ${OSID} | tr '[A-Z]' '[a-z]') case "$lowercase_osid" in ubuntu) pre_cmd="${SUDO_CMD} apt-get install -y ffmpeg" ;; centos) pre_cmd="${SUDO_CMD} yum install -y ffmpeg" ;; debian) pre_cmd="${SUDO_CMD} apt-get install -y ffmpeg" ;; \"alios\") pre_cmd="${SUDO_CMD} yum install -y ffmpeg" ;; \"alinux\") pre_cmd="${SUDO_CMD} yum install -y ffmpeg" ;; *) echo -e " ${RED}$lowercase_osid is not supported.${PLAIN}" ;; esac echo -e " Run ${BLUE}${pre_cmd}${PLAIN}" echo pre_cmd="pip3 install ffmpeg-python" echo -e " Run ${BLUE}${pre_cmd}${PLAIN}" $pre_cmd echo } deploySamples(){ if [ ! -d $PARAMS_FUNASR_SAMPLES_LOCAL_DIR ]; then echo -e "${YELLOW}Downloading samples to${PLAIN} ${CYAN}${PARAMS_FUNASR_LOCAL_WORKSPACE}${PLAIN} ${YELLOW}...${PLAIN}" download_cmd="curl ${DEFAULT_SAMPLES_URL} -o ${PARAMS_FUNASR_SAMPLES_LOCAL_PATH}" untar_cmd="tar -zxf ${PARAMS_FUNASR_SAMPLES_LOCAL_PATH} -C ${PARAMS_FUNASR_LOCAL_WORKSPACE}" if [ ! -f "$PARAMS_FUNASR_SAMPLES_LOCAL_PATH" ]; then $download_cmd fi $untar_cmd echo installPythonDependencyForPython echo fi } getDockerId(){ id="" array=($(${SUDO_CMD} docker ps -a | grep ${PARAMS_DOCKER_IMAGE} | awk '{print $1}')) len=${#array[@]} if [ $len -ge 1 ]; then # get the first id id=$array if [ ! -z "$id" ]; then PARAMS_FUNASR_DOCKER_ID=$id fi fi } checkDockerImageExist(){ result=1 if [ -z "$PARAMS_DOCKER_IMAGE" ]; then return 50 else result=$(${SUDO_CMD} docker ps | grep ${PARAMS_DOCKER_IMAGE} | wc -l) fi result=`expr ${result} + 0` echo "checkDockerImageExist result0: " $result if [ $result -ne 0 ]; then # found docker return 51 else return 0 fi } checkDockerIdExist(){ result=0 if [ -z "$PARAMS_FUNASR_DOCKER_ID" ]; then if [ -z "$PARAMS_DOCKER_IMAGE" ]; then return 63 else return 60 fi else if [ -z "$PARAMS_DOCKER_IMAGE" ]; then return 61 else if [ "$1" = "install" ]; then result=$(${SUDO_CMD} docker ps -a | grep ${PARAMS_DOCKER_IMAGE} | grep ${PARAMS_FUNASR_DOCKER_ID} | wc -l) else result=$(${SUDO_CMD} docker ps | grep ${PARAMS_DOCKER_IMAGE} | grep ${PARAMS_FUNASR_DOCKER_ID} | wc -l) fi fi fi result=`expr ${result} + 0` if [ $result -eq 1 ]; then # found docker return 62 else return 0 fi } dockerStop(){ if [ -z "$PARAMS_FUNASR_DOCKER_ID" ]; then echo -e " ${RED}DOCKER_ID is empty, cannot stop docker.${PLAIN}" else echo -e " ${YELLOW}Stop docker(${PLAIN}${GREEN}${PARAMS_DOCKER_IMAGE} ${PARAMS_FUNASR_DOCKER_ID}${PLAIN}${YELLOW}) server ...${PLAIN}" ${SUDO_CMD} docker stop ${PARAMS_FUNASR_DOCKER_ID} fi echo } dockerRemove(){ if [ -z "$PARAMS_FUNASR_DOCKER_ID" ]; then echo -e " ${RED}DOCKER_ID is empty, cannot remove docker.${PLAIN}" else echo -e " ${YELLOW}Remove docker(${PLAIN}${GREEN}${PARAMS_DOCKER_IMAGE} ${PARAMS_FUNASR_DOCKER_ID}${PLAIN}${YELLOW}) ...${PLAIN}" ${SUDO_CMD} docker rm ${PARAMS_FUNASR_DOCKER_ID} fi echo } modelChange(){ model_type=$1 model_id=$2 local_flag=0 relativePathToFullPath $model_id if [ -d "$full_path" ]; then local_flag=1 model_id=$full_path else local_flag=0 fi full_path="" result=$(echo ${model_type} | grep "\-\-asr_model") if [ "$result" != "" ]; then if [ $local_flag -eq 0 ]; then PARAMS_ASR_ID=$model_id PARAMS_DOCKER_ASR_PATH=${PARAMS_DOWNLOAD_MODEL_DIR}/${PARAMS_ASR_ID} PARAMS_DOCKER_ASR_DIR=$(dirname "${PARAMS_DOCKER_ASR_PATH}") PARAMS_LOCAL_ASR_PATH=${PARAMS_FUNASR_LOCAL_MODELS_DIR}/${PARAMS_ASR_ID} PARAMS_LOCAL_ASR_DIR=$(dirname "${PARAMS_LOCAL_ASR_PATH}") else PARAMS_ASR_ID="" PARAMS_LOCAL_ASR_PATH=$model_id if [ ! -d "$PARAMS_LOCAL_ASR_PATH" ]; then echo -e " ${RED}${PARAMS_LOCAL_ASR_PATH} does not exist, please set again.${PLAIN}" else model_name=$(basename "${PARAMS_LOCAL_ASR_PATH}") PARAMS_LOCAL_ASR_DIR=$(dirname "${PARAMS_LOCAL_ASR_PATH}") PARAMS_DOCKER_ASR_DIR=$PARAMS_DOWNLOAD_MODEL_DIR PARAMS_DOCKER_ASR_PATH=${PARAMS_DOCKER_ASR_DIR}/${model_name} fi fi fi result=$(echo ${model_type} | grep "\-\-vad_model") if [ "$result" != "" ]; then if [ $local_flag -eq 0 ]; then PARAMS_VAD_ID=$model_id PARAMS_DOCKER_VAD_PATH=${PARAMS_DOWNLOAD_MODEL_DIR}/${PARAMS_VAD_ID} PARAMS_DOCKER_VAD_DIR=$(dirname "${PARAMS_DOCKER_VAD_PATH}") PARAMS_LOCAL_VAD_PATH=${PARAMS_FUNASR_LOCAL_MODELS_DIR}/${PARAMS_VAD_ID} PARAMS_LOCAL_VAD_DIR=$(dirname "${PARAMS_LOCAL_VAD_PATH}") else PARAMS_VAD_ID="" PARAMS_LOCAL_VAD_PATH=$model_id if [ ! -d "$PARAMS_LOCAL_VAD_PATH" ]; then echo -e " ${RED}${PARAMS_LOCAL_VAD_PATH} does not exist, please set again.${PLAIN}" else model_name=$(basename "${PARAMS_LOCAL_VAD_PATH}") PARAMS_LOCAL_VAD_DIR=$(dirname "${PARAMS_LOCAL_VAD_PATH}") PARAMS_DOCKER_VAD_DIR=$PARAMS_DOWNLOAD_MODEL_DIR PARAMS_DOCKER_VAD_PATH=${PARAMS_DOCKER_VAD_DIR}/${model_name} fi fi fi result=$(echo ${model_type} | grep "\-\-punc_model") if [ "$result" != "" ]; then if [ $local_flag -eq 0 ]; then PARAMS_PUNC_ID=$model_id PARAMS_DOCKER_PUNC_PATH=${PARAMS_DOWNLOAD_MODEL_DIR}/${PARAMS_PUNC_ID} PARAMS_DOCKER_PUNC_DIR=$(dirname "${PARAMS_DOCKER_PUNC_PATH}") PARAMS_LOCAL_PUNC_PATH=${PARAMS_FUNASR_LOCAL_MODELS_DIR}/${PARAMS_PUNC_ID} PARAMS_LOCAL_PUNC_DIR=$(dirname "${PARAMS_LOCAL_PUNC_PATH}") else model_name=$(basename "${PARAMS_LOCAL_PUNC_PATH}") PARAMS_LOCAL_PUNC_DIR=$(dirname "${PARAMS_LOCAL_PUNC_PATH}") PARAMS_DOCKER_PUNC_DIR=$PARAMS_DOWNLOAD_MODEL_DIR PARAMS_DOCKER_PUNC_PATH=${PARAMS_DOCKER_PUNC_DIR}/${model_name} fi fi } threadNumChange() { type=$1 val=$2 if [ -z "$val"]; then num=`expr ${val} + 0` if [ $num -ge 1 ] && [ $num -le 1024 ]; then result=$(echo ${type} | grep "\-\-decode_thread_num") if [ "$result" != "" ]; then PARAMS_DECODER_THREAD_NUM=$num fi result=$(echo ${type} | grep "\-\-io_thread_num") if [ "$result" != "" ]; then PARAMS_IO_THREAD_NUM=$num fi fi fi } portChange() { type=$1 val=$2 if [ ! -z "$val" ]; then port=`expr ${val} + 0` if [ $port -ge 1 ] && [ $port -le 65536 ]; then result=$(echo ${type} | grep "host_port") if [ "$result" != "" ]; then PARAMS_HOST_PORT=$port fi result=$(echo ${type} | grep "docker_port") if [ "$result" != "" ]; then PARAMS_DOCKER_PORT=$port fi fi fi } sampleClientRun(){ echo -e "${YELLOW}Will download sample tools for the client to show how speech recognition works.${PLAIN}" download_cmd="curl ${DEFAULT_SAMPLES_URL} -o ${PARAMS_FUNASR_SAMPLES_LOCAL_PATH}" untar_cmd="tar -zxf ${PARAMS_FUNASR_SAMPLES_LOCAL_PATH} -C ${PARAMS_FUNASR_LOCAL_WORKSPACE}" if [ ! -f "$PARAMS_FUNASR_SAMPLES_LOCAL_PATH" ]; then $download_cmd fi if [ -f "$PARAMS_FUNASR_SAMPLES_LOCAL_PATH" ]; then $untar_cmd fi if [ -d "$PARAMS_FUNASR_SAMPLES_LOCAL_DIR" ]; then echo -e " Please select the client you want to run." menuSelection ${SAMPLE_CLIENTS[*]} result=$? index=`expr ${result} - 1` lang=${SAMPLE_CLIENTS[${index}]} echo server_ip="127.0.0.1" echo -e " Please enter the IP of server, default(${CYAN}${server_ip}${PLAIN}): \c" read server_ip if [ -z "$server_ip" ]; then server_ip="127.0.0.1" fi host_port=`sed '/^PARAMS_HOST_PORT=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ -z "$host_port" ]; then host_port="10095" fi echo -e " Please enter the port of server, default(${CYAN}${host_port}${PLAIN}): \c" read host_port if [ -z "$host_port" ]; then host_port=`sed '/^PARAMS_HOST_PORT=/!d;s/.*=//' ${DEFAULT_FUNASR_CONFIG_FILE}` if [ -z "$host_port" ]; then host_port="10095" fi fi wav_path="${PARAMS_FUNASR_SAMPLES_LOCAL_DIR}/audio/asr_example.wav" echo -e " Please enter the audio path, default(${CYAN}${wav_path}${PLAIN}): \c" read WAV_PATH if [ -z "$wav_path" ]; then wav_path="${PARAMS_FUNASR_SAMPLES_LOCAL_DIR}/audio/asr_example.wav" fi echo pre_cmd=”“ case "$lang" in Linux_Cpp) client_exec="${PARAMS_FUNASR_SAMPLES_LOCAL_DIR}/cpp/funasr-wss-client" run_cmd="${client_exec} --server-ip ${server_ip} --port ${host_port} --wav-path ${wav_path}" ;; Python) client_exec="${PARAMS_FUNASR_SAMPLES_LOCAL_DIR}/python/wss_client_asr.py" run_cmd="python3 ${client_exec} --host ${server_ip} --port ${host_port} --mode offline --audio_in ${wav_path} --send_without_sleep --output_dir ${PARAMS_FUNASR_SAMPLES_LOCAL_DIR}/python" pre_cmd="pip3 install click>=8.0.4" echo -e " Run ${BLUE}${pre_cmd}${PLAIN}" $pre_cmd echo pre_cmd="pip3 install -r ${PARAMS_FUNASR_SAMPLES_LOCAL_DIR}/python/requirements_client.txt" echo -e " Run ${BLUE}${pre_cmd}${PLAIN}" $pre_cmd echo ;; *) echo "${lang} is not supported." ;; esac echo -e " Run ${BLUE}${run_cmd}${PLAIN}" $run_cmd echo echo -e " If failed, you can try (${GREEN}${run_cmd}${PLAIN}) in your Shell." echo fi } paramsConfigure(){ initConfiguration initParameters selectDockerImages selectModels result=$? result=`expr ${result} + 0` if [ $result -ne 0 ]; then return $result fi setupHostPort complementParameters return 0 } # Display Help info displayHelp(){ echo -e "${UNDERLINE}Usage${PLAIN}:" echo -e " $0 [OPTIONAL FLAGS]" echo echo -e "funasr-runtime-deploy-offline-cpu-en.sh - a Bash script to install&run FunASR docker." echo echo -e "${UNDERLINE}Options${PLAIN}:" echo -e " ${BOLD}-i, install, --install${PLAIN} Install and run FunASR docker." echo -e " install [--workspace] <workspace in local>" echo -e " install [--ssl] <0: close SSL; 1: open SSL, default:1>" echo -e " ${BOLD}-s, start , --start${PLAIN} Run FunASR docker with configuration that has already been set." echo -e " ${BOLD}-p, stop , --stop${PLAIN} Stop FunASR docker." echo -e " ${BOLD}-m, remove , --remove${PLAIN} Remove FunASR docker installed." echo -e " ${BOLD}-r, restart, --restart${PLAIN} Restart FunASR docker." echo -e " ${BOLD}-u, update , --update${PLAIN} Update parameters that has already been set." echo -e " update [--workspace] <workspace in local>" echo -e " update [--asr_model | --vad_model | --punc_model] <model_id or local model path>" echo -e " update [--host_port | --docker_port] <port number>" echo -e " update [--decode_thread_num | io_thread_num] <the number of threads>" echo -e " update [--ssl] <0: close SSL; 1: open SSL, default:1>" echo -e " ${BOLD}-c, client , --client${PLAIN} Get a client example to show how to initiate speech recognition." echo -e " ${BOLD}-o, show , --show${PLAIN} Displays all parameters that have been set." echo -e " ${BOLD}-v, version, --version${PLAIN} Display current script version." echo -e " ${BOLD}-h, help , --help${PLAIN} Display this help." echo echo -e " Version : ${scriptVersion} " echo -e " Modify Date: ${scriptDate}" } parseInput(){ local menu menu=($(echo "$@")) len=${#menu[@]} stage="" if [ $len -ge 2 ]; then for val in ${menu[@]} do result=$(echo $val | grep "\-\-") if [ "$result" != "" ]; then stage=$result else if [ "$stage" = "--workspace" ]; then relativePathToFullPath $val PARAMS_FUNASR_LOCAL_WORKSPACE=$full_path full_path="" if [ ! -z "$PARAMS_FUNASR_LOCAL_WORKSPACE" ]; then mkdir -p $PARAMS_FUNASR_LOCAL_WORKSPACE fi elif [ "$stage" = "--ssl" ]; then PARAMS_SSL_FLAG=`expr ${val} + 0` fi fi done fi } # OS OSID=$(grep ^ID= /etc/os-release | cut -d= -f2) OSVER=$(lsb_release -cs) OSNUM=$(grep -oE "[0-9.]+" /etc/issue) CPUNUM=$(cat /proc/cpuinfo | grep "processor"|wc -l) DOCKERINFO=$(${SUDO_CMD} docker info | wc -l) DOCKERINFOLEN=`expr ${DOCKERINFO} + 0` # PARAMS # The workspace for FunASR in local PARAMS_FUNASR_LOCAL_WORKSPACE=$DEFAULT_FUNASR_LOCAL_WORKSPACE # The dir stored sample code in local PARAMS_FUNASR_SAMPLES_LOCAL_DIR=${PARAMS_FUNASR_LOCAL_WORKSPACE}/${DEFAULT_SAMPLES_DIR} # The path of sample code in local PARAMS_FUNASR_SAMPLES_LOCAL_PATH=${PARAMS_FUNASR_LOCAL_WORKSPACE}/${DEFAULT_SAMPLES_NAME}.tar.gz # The dir stored models in local PARAMS_FUNASR_LOCAL_MODELS_DIR="${PARAMS_FUNASR_LOCAL_WORKSPACE}/models" # The id of started docker PARAMS_FUNASR_DOCKER_ID="" # The server excutor in local PARAMS_DOCKER_EXEC_PATH=$DEFAULT_DOCKER_EXEC_PATH # The dir stored server excutor in docker PARAMS_DOCKER_EXEC_DIR=$DEFAULT_DOCKER_EXEC_DIR # The dir for downloading model in docker PARAMS_DOWNLOAD_MODEL_DIR=$DEFAULT_FUNASR_WORKSPACE_DIR # The Docker image name PARAMS_DOCKER_IMAGE="" # The dir stored punc model in local PARAMS_LOCAL_PUNC_DIR="" # The path of punc model in local PARAMS_LOCAL_PUNC_PATH="" # The dir stored punc model in docker PARAMS_DOCKER_PUNC_DIR="" # The path of punc model in docker PARAMS_DOCKER_PUNC_PATH="" # The punc model ID in ModelScope PARAMS_PUNC_ID="damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx" # The dir stored vad model in local PARAMS_LOCAL_VAD_DIR="" # The path of vad model in local PARAMS_LOCAL_VAD_PATH="" # The dir stored vad model in docker PARAMS_DOCKER_VAD_DIR="" # The path of vad model in docker PARAMS_DOCKER_VAD_PATH="" # The vad model ID in ModelScope PARAMS_VAD_ID="damo/speech_fsmn_vad_zh-cn-16k-common-onnx" # The dir stored asr model in local PARAMS_LOCAL_ASR_DIR="" # The path of asr model in local PARAMS_LOCAL_ASR_PATH="" # The dir stored asr model in docker PARAMS_DOCKER_ASR_DIR="" # The path of asr model in docker PARAMS_DOCKER_ASR_PATH="" # The asr model ID in ModelScope PARAMS_ASR_ID="damo/speech_paraformer-large_asr_nat-en-16k-common-vocab10020-onnx" PARAMS_HOST_PORT="10095" PARAMS_DOCKER_PORT="10095" PARAMS_DECODER_THREAD_NUM="32" PARAMS_IO_THREAD_NUM="8" PARAMS_SSL_FLAG=1 echo -e "#############################################################" echo -e "# ${RED}OS${PLAIN}: ${OSID} ${OSNUM} ${OSVER}" echo -e "# ${RED}Kernel${PLAIN}: $(uname -m) Linux $(uname -r)" echo -e "# ${RED}CPU${PLAIN}: $(grep 'model name' /proc/cpuinfo | uniq | awk -F : '{print $2}' | sed 's/^[ \t]*//g' | sed 's/ \+/ /g') " echo -e "# ${RED}CPU NUM${PLAIN}: ${CPUNUM}" echo -e "# ${RED}RAM${PLAIN}: $(cat /proc/meminfo | grep 'MemTotal' | awk -F : '{print $2}' | sed 's/^[ \t]*//g') " echo -e "#" echo -e "# ${RED}Version${PLAIN}: ${scriptVersion} " echo -e "# ${RED}Modify Date${PLAIN}: ${scriptDate}" echo -e "#############################################################" echo # Initialization step case "$1" in install|-i|--install) rootNess paramsFromDefault parseInput $@ paramsConfigure result=$? result=`expr ${result} + 0` if [ $result -eq 0 ]; then showAllParams "install" installFunasrDocker dockerRun "install" result=$? try_count=1 while true do stage=`expr ${result} + 0` if [ $try_count -ge 10 ]; then break else # 98: cannot find progress from Docker if [ $stage -eq 98 ]; then dockerStop dockerRun "start" result=$? let try_count=try_count+1 else break fi fi done fi ;; start|-s|--start) rootNess paramsFromDefault showAllParams "only_show" dockerRun "start" result=$? try_count=1 while true do stage=`expr ${result} + 0` if [ $try_count -ge 10 ]; then break else # 98: cannot find progress from Docker if [ $stage -eq 98 ]; then dockerStop dockerRun "start" result=$? let try_count=try_count+1 else break fi fi done ;; restart|-r|--restart) rootNess paramsFromDefault showAllParams "only_show" dockerStop dockerRun "start" result=$? try_count=1 while true do stage=`expr ${result} + 0` if [ $try_count -ge 10 ]; then break else # 98: cannot find progress from Docker if [ $stage -eq 98 ]; then dockerStop dockerRun "start" result=$? let try_count=try_count+1 else break fi fi done ;; stop|-p|--stop) rootNess paramsFromDefault dockerStop ;; remove|-m|--remove) rootNess paramsFromDefault dockerStop dockerRemove rm -f ${DEFAULT_FUNASR_CONFIG_FILE} rm -f ${DEFAULT_FUNASR_SERVER_CONFIG_FILE} ;; update|-u|--update) rootNess paramsFromDefault if [ $# -eq 3 ]; then type=$2 val=$3 if [ "$type" = "--asr_model" ] || [ "$type" = "--vad_model" ] || [ "$type" = "--punc_model" ]; then modelChange $type $val elif [ "$type" = "--decode_thread_num" ] || [ "$type" = "--io_thread_num" ]; then threadNumChange $type $val elif [ "$type" = "--host_port" ] || [ "$type" = "--docker_port" ]; then portChange $type $val elif [ "$type" = "--workspace" ]; then relativePathToFullPath $val PARAMS_FUNASR_LOCAL_WORKSPACE=$full_path if [ ! -z "$PARAMS_FUNASR_LOCAL_WORKSPACE" ]; then mkdir -p $PARAMS_FUNASR_LOCAL_WORKSPACE fi elif [ "$type" = "--ssl" ]; then switch=`expr ${val} + 0` if [ $switch -eq 0 ]; then PARAMS_SSL_FLAG=0 else PARAMS_SSL_FLAG=1 fi else displayHelp fi else displayHelp fi initParameters complementParameters showAllParams "install" dockerStop dockerRun "start" result=$? try_count=1 while true do stage=`expr ${result} + 0` if [ $try_count -ge 10 ]; then break else # 98: cannot find progress from Docker # 60: DOCKER_ID is empty if [ $stage -eq 98 ] || [ $stage -eq 60 ]; then dockerStop dockerRun "start" result=$? let try_count=try_count+1 else break fi fi done ;; client|-c|--client) rootNess paramsFromDefault parseInput $@ sampleClientRun ;; show|-o|--show) rootNess paramsFromDefault showAllParams "only_show" ;; *) displayHelp exit 0 ;; esac funasr/runtime/docs/SDK_advanced_guide_offline_en.md
New file @@ -0,0 +1,211 @@ # Advanced Development Guide (File transcription service) FunASR provides a English offline file transcription service that can be deployed locally or on a cloud server with just one click. The core of the service is the FunASR runtime SDK, which has been open-sourced. FunASR-runtime combines various capabilities such as speech endpoint detection (VAD), large-scale speech recognition (ASR) using Paraformer-large, and punctuation detection (PUNC), which have all been open-sourced by the speech laboratory of DAMO Academy on the Modelscope community. This enables accurate and efficient high-concurrency transcription of audio files. This document serves as a development guide for the FunASR offline file transcription service. If you wish to quickly experience the offline file transcription service, please refer to the one-click deployment example for the FunASR offline file transcription service ([docs](./SDK_tutorial.md)). ## Installation of Docker The following steps are for manually installing Docker and Docker images. If your Docker image has already been launched, you can ignore this step. ### Installation of Docker environment ```shell # Ubuntu: curl -fsSL https://test.docker.com -o test-docker.sh sudo sh test-docker.sh # Debian: curl -fsSL https://get.docker.com -o get-docker.sh sudo sh get-docker.sh # CentOS: curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun # MacOS: brew install --cask --appdir=/Applications docker ``` More details could ref to [docs](https://alibaba-damo-academy.github.io/FunASR/en/installation/docker.html) ### Starting Docker ```shell sudo systemctl start docker ``` ### Pulling and launching images Use the following command to pull and launch the Docker image for the FunASR runtime-SDK: ```shell sudo docker pull registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-en-cpu-0.1.0 sudo docker run -p 10095:10095 -it --privileged=true -v /root:/workspace/models registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-en-cpu-0.1.0 ``` Introduction to command parameters: ```text -p <host port>:<mapped docker port>: In the example, host machine (ECS) port 10095 is mapped to port 10095 in the Docker container. Make sure that port 10095 is open in the ECS security rules. -v <host path>:<mounted Docker path>: In the example, the host machine path /root is mounted to the Docker path /workspace/models. ``` ## Starting the server Use the flollowing script to start the server : ```shell nohup bash run_server.sh \ --download-model-dir /workspace/models \ --vad-dir damo/speech_fsmn_vad_zh-cn-16k-common-onnx \ --model-dir damo/speech_paraformer-large_asr_nat-en-16k-common-vocab10020-onnx \ --punc-dir damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx > log.out 2>&1 & # If you want to close ssl,please add:--certfile 0 ``` More details about the script run_server.sh: The FunASR-wss-server supports downloading models from Modelscope. You can set the model download address (--download-model-dir, default is /workspace/models) and the model ID (--model-dir, --vad-dir, --punc-dir). Here is an example: ```shell cd /workspace/FunASR/funasr/runtime/websocket/build/bin ./funasr-wss-server \ --download-model-dir /workspace/models \ --model-dir damo/speech_paraformer-large_asr_nat-en-16k-common-vocab10020-onnx \ --vad-dir damo/speech_fsmn_vad_zh-cn-16k-common-onnx \ --punc-dir damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx \ --decoder-thread-num 32 \ --io-thread-num 8 \ --port 10095 \ --certfile ../../../ssl_key/server.crt \ --keyfile ../../../ssl_key/server.key ``` Introduction to command parameters: ```text --download-model-dir: Model download address, download models from Modelscope by setting the model ID. --model-dir: Modelscope model ID. --quantize: True for quantized ASR model, False for non-quantized ASR model. Default is True. --vad-dir: Modelscope model ID. --vad-quant: True for quantized VAD model, False for non-quantized VAD model. Default is True. --punc-dir: Modelscope model ID. --punc-quant: True for quantized PUNC model, False for non-quantized PUNC model. Default is True. --itn-dir modelscope model ID --port: Port number that the server listens on. Default is 10095. --decoder-thread-num: Number of inference threads that the server starts. Default is 8. --io-thread-num: Number of IO threads that the server starts. Default is 1. --certfile <string>: SSL certificate file. Default is ../../../ssl_key/server.crt. If you want to close ssl,set "" --keyfile <string>: SSL key file. Default is ../../../ssl_key/server.key. If you want to close ssl,set "" ``` The FunASR-wss-server also supports loading models from a local path (see Preparing Model Resources for detailed instructions on preparing local model resources). Here is an example: ```shell cd /workspace/FunASR/funasr/runtime/websocket/build/bin ./funasr-wss-server \ --model-dir /workspace/models/damo/speech_paraformer-large_asr_nat-en-16k-common-vocab10020-onnx \ --vad-dir /workspace/models/damo/speech_fsmn_vad_zh-cn-16k-common-onnx \ --punc-dir /workspace/models/damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx \ --decoder-thread-num 32 \ --io-thread-num 8 \ --port 10095 \ --certfile ../../../ssl_key/server.crt \ --keyfile ../../../ssl_key/server.key ``` After executing the above command, the real-time speech transcription service will be started. If the model is specified as a ModelScope model id, the following models will be automatically downloaded from ModelScope: [FSMN-VAD](https://www.modelscope.cn/models/damo/speech_fsmn_vad_zh-cn-16k-common-onnx/summary) [Paraformer-lagre](https://www.modelscope.cn/models/damo/speech_paraformer-large_asr_nat-en-16k-common-vocab10020-onnx/summary) [CT-Transformer](https://www.modelscope.cn/models/damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx/summary) If you wish to deploy your fine-tuned model (e.g., 10epoch.pb), you need to manually rename the model to model.pb and replace the original model.pb in ModelScope. Then, specify the path as `model_dir`. ## Starting the client After completing the deployment of FunASR offline file transcription service on the server, you can test and use the service by following these steps. Currently, FunASR-bin supports multiple ways to start the client. The following are command-line examples based on python-client, c++-client, and custom client Websocket communication protocol: ### python-client ```shell python funasr_wss_client.py --host "127.0.0.1" --port 10095 --mode offline --audio_in "./data/wav.scp" --send_without_sleep --output_dir "./results" ``` Introduction to command parameters: ```text --host: the IP address of the server. It can be set to 127.0.0.1 for local testing. --port: the port number of the server listener. --audio_in: the audio input. Input can be a path to a wav file or a wav.scp file (a Kaldi-formatted wav list in which each line includes a wav_id followed by a tab and a wav_path). --output_dir: the path to the recognition result output. --ssl: whether to use SSL encryption. The default is to use SSL. --mode: offline mode. --hotword: If am is hotword model, setting hotword: *.txt(one hotword perline) or hotwords seperate by space (could be: 阿里巴巴 达摩院) --use_itn: whether to use itn, the default value is 1 for enabling and 0 for disabling. ``` ### c++-client ```shell . /funasr-wss-client --server-ip 127.0.0.1 --port 10095 --wav-path test.wav --thread-num 1 --is-ssl 1 ``` Introduction to command parameters: ```text --server-ip: the IP address of the server. It can be set to 127.0.0.1 for local testing. --port: the port number of the server listener. --wav-path: the audio input. Input can be a path to a wav file or a wav.scp file (a Kaldi-formatted wav list in which each line includes a wav_id followed by a tab and a wav_path). --is-ssl: whether to use SSL encryption. The default is to use SSL. --hotword: If am is hotword model, setting hotword: *.txt(one hotword perline) or hotwords seperate by space (could be: 阿里巴巴 达摩院) --use-itn: whether to use itn, the default value is 1 for enabling and 0 for disabling. ``` ### Custom client If you want to define your own client, see the [Websocket communication protocol](./websocket_protocol.md) ## How to customize service deployment The code for FunASR-runtime is open source. If the server and client cannot fully meet your needs, you can further develop them based on your own requirements: ### C++ client https://github.com/alibaba-damo-academy/FunASR/tree/main/funasr/runtime/websocket ### Python client https://github.com/alibaba-damo-academy/FunASR/tree/main/funasr/runtime/python/websocket ### C++ server #### VAD ```c++ // The use of the VAD model consists of two steps: FsmnVadInit and FsmnVadInfer: FUNASR_HANDLE vad_hanlde=FsmnVadInit(model_path, thread_num); // Where: model_path contains "model-dir" and "quantize", thread_num is the ONNX thread count; FUNASR_RESULT result=FsmnVadInfer(vad_hanlde, wav_file.c_str(), NULL, 16000); // Where: vad_hanlde is the return value of FunOfflineInit, wav_file is the path to the audio file, and sampling_rate is the sampling rate (default 16k). ``` See the usage example for details [docs](https://github.com/alibaba-damo-academy/FunASR/blob/main/funasr/runtime/onnxruntime/bin/funasr-onnx-offline-vad.cpp) #### ASR ```text // The use of the ASR model consists of two steps: FunOfflineInit and FunOfflineInfer: FUNASR_HANDLE asr_hanlde=FunOfflineInit(model_path, thread_num); // Where: model_path contains "model-dir" and "quantize", thread_num is the ONNX thread count; FUNASR_RESULT result=FunOfflineInfer(asr_hanlde, wav_file.c_str(), RASR_NONE, NULL, 16000); // Where: asr_hanlde is the return value of FunOfflineInit, wav_file is the path to the audio file, and sampling_rate is the sampling rate (default 16k). ``` See the usage example for details, [docs](https://github.com/alibaba-damo-academy/FunASR/blob/main/funasr/runtime/onnxruntime/bin/funasr-onnx-offline.cpp) #### PUNC ```text // The use of the PUNC model consists of two steps: CTTransformerInit and CTTransformerInfer: FUNASR_HANDLE punc_hanlde=CTTransformerInit(model_path, thread_num); // Where: model_path contains "model-dir" and "quantize", thread_num is the ONNX thread count; FUNASR_RESULT result=CTTransformerInfer(punc_hanlde, txt_str.c_str(), RASR_NONE, NULL); // Where: punc_hanlde is the return value of CTTransformerInit, txt_str is the text ``` See the usage example for details, [docs](https://github.com/alibaba-damo-academy/FunASR/blob/main/funasr/runtime/onnxruntime/bin/funasr-onnx-offline-punc.cpp) funasr/runtime/docs/SDK_advanced_guide_offline_en_zh.md
New file @@ -0,0 +1,271 @@ # FunASR英文离线文件转写服务开发指南 FunASR提供可一键本地或者云端服务器部署的英文离线文件转写服务,内核为FunASR已开源runtime-SDK。FunASR-runtime结合了达摩院语音实验室在Modelscope社区开源的语音端点检测(VAD)、Paraformer-large语音识别(ASR)、标点检测(PUNC) 等相关能力,可以准确、高效的对音频进行高并发转写。 本文档为FunASR离线文件转写服务开发指南。如果您想快速体验离线文件转写服务,可参考[快速上手](#快速上手)。 ## 服务器配置 用户可以根据自己的业务需求,选择合适的服务器配置,推荐配置为: - 配置1: (X86,计算型),4核vCPU,内存8G,单机可以支持大约32路的请求 - 配置2: (X86,计算型),16核vCPU,内存32G,单机可以支持大约64路的请求 - 配置3: (X86,计算型),64核vCPU,内存128G,单机可以支持大约200路的请求 详细性能测试报告([点击此处](./benchmark_onnx_cpp.md)) 云服务厂商,针对新用户,有3个月免费试用活动,申请教程([点击此处](https://github.com/alibaba-damo-academy/FunASR/blob/main/funasr/runtime/docs/aliyun_server_tutorial.md)) ## 快速上手 ### 镜像启动 通过下述命令拉取并启动FunASR runtime-SDK的docker镜像: ```shell sudo docker pull \ registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-en-cpu-0.1.0 mkdir -p ./funasr-runtime-resources/models sudo docker run -p 10095:10095 -it --privileged=true \ -v $PWD/funasr-runtime-resources/models:/workspace/models \ registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-en-cpu-0.1.0 ``` 如果您没有安装docker,可参考[Docker安装](#Docker安装) ### 服务端启动 docker启动之后,启动 funasr-wss-server服务程序: ```shell cd FunASR/funasr/runtime nohup bash run_server.sh \ --download-model-dir /workspace/models \ --vad-dir damo/speech_fsmn_vad_zh-cn-16k-common-onnx \ --model-dir damo/speech_paraformer-large_asr_nat-en-16k-common-vocab10020-onnx \ --punc-dir damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx > log.out 2>&1 & # 如果您想关闭ssl,增加参数:--certfile 0 ``` 服务端详细参数介绍可参考[服务端参数介绍](#服务端参数介绍) ### 客户端测试与使用 下载客户端测试工具目录samples ```shell wget https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/sample/funasr_samples.tar.gz ``` 我们以Python语言客户端为例,进行说明,支持多种音频格式输入(.wav, .pcm, .mp3等),也支持视频输入(.mp4等),以及多文件列表wav.scp输入,其他版本客户端请参考文档([点击此处](#客户端用法详解)),定制服务部署请参考[如何定制服务部署](#如何定制服务部署) ```shell python3 funasr_wss_client.py --host "127.0.0.1" --port 10095 --mode offline --audio_in "../audio/asr_example.wav" ``` ------------------ ## Docker安装 下述步骤为手动安装docker环境的步骤: ### docker环境安装 ```shell # Ubuntu: curl -fsSL https://test.docker.com -o test-docker.sh sudo sh test-docker.sh # Debian: curl -fsSL https://get.docker.com -o get-docker.sh sudo sh get-docker.sh # CentOS: curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun # MacOS: brew install --cask --appdir=/Applications docker ``` 安装详见:https://alibaba-damo-academy.github.io/FunASR/en/installation/docker.html ### docker启动 ```shell sudo systemctl start docker ``` ## 客户端用法详解 在服务器上完成FunASR服务部署以后,可以通过如下的步骤来测试和使用离线文件转写服务。 目前分别支持以下几种编程语言客户端 - [Python](#python-client) - [CPP](#cpp-client) - [html网页版本](#Html网页版) - [Java](#Java-client) ### python-client 若想直接运行client进行测试,可参考如下简易说明,以python版本为例: ```shell python3 funasr_wss_client.py --host "127.0.0.1" --port 10095 --mode offline \ --audio_in "../audio/asr_example.wav" --output_dir "./results" ``` 命令参数说明: ```text --host 为FunASR runtime-SDK服务部署机器ip,默认为本机ip(127.0.0.1),如果client与服务不在同一台服务器, 需要改为部署机器ip --port 10095 部署端口号 --mode offline表示离线文件转写 --audio_in 需要进行转写的音频文件,支持文件路径,文件列表wav.scp --thread_num 设置并发发送线程数,默认为1 --ssl 设置是否开启ssl证书校验,默认1开启,设置为0关闭 --hotword 如果模型为热词模型,可以设置热词: *.txt(每行一个热词) 或者空格分隔的热词字符串(阿里巴巴 达摩院) --use_itn 设置是否使用itn,默认1开启,设置为0关闭 ``` ### cpp-client 进入samples/cpp目录后,可以用cpp进行测试,指令如下: ```shell ./funasr-wss-client --server-ip 127.0.0.1 --port 10095 --wav-path ../audio/asr_example.wav ``` 命令参数说明: ```text --server-ip 为FunASR runtime-SDK服务部署机器ip,默认为本机ip(127.0.0.1),如果client与服务不在同一台服务器, 需要改为部署机器ip --port 10095 部署端口号 --wav-path 需要进行转写的音频文件,支持文件路径 --hotword 如果模型为热词模型,可以设置热词: *.txt(每行一个热词) 或者空格分隔的热词字符串 (阿里巴巴 达摩院) --use-itn 设置是否使用itn,默认1开启,设置为0关闭 ``` ### Html网页版 在浏览器中打开 html/static/index.html,即可出现如下页面,支持麦克风输入与文件上传,直接进行体验 <img src="images/html.png" width="900"/> ### Java-client ```shell FunasrWsClient --host localhost --port 10095 --audio_in ./asr_example.wav --mode offline ``` 详细可以参考文档([点击此处](../java/readme.md)) ## 服务端参数介绍: funasr-wss-server支持从Modelscope下载模型,设置模型下载地址(--download-model-dir,默认为/workspace/models)及model ID(--model-dir、--vad-dir、--punc-dir),示例如下: ```shell cd /workspace/FunASR/funasr/runtime/websocket/build/bin ./funasr-wss-server \ --download-model-dir /workspace/models \ --model-dir damo/speech_paraformer-large_asr_nat-en-16k-common-vocab10020-onnx \ --vad-dir damo/speech_fsmn_vad_zh-cn-16k-common-onnx \ --punc-dir damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx \ --decoder-thread-num 32 \ --io-thread-num 8 \ --port 10095 \ --certfile ../../../ssl_key/server.crt \ --keyfile ../../../ssl_key/server.key ``` 命令参数介绍: ```text --download-model-dir 模型下载地址,通过设置model ID从Modelscope下载模型 --model-dir modelscope model ID --quantize True为量化ASR模型,False为非量化ASR模型,默认是True --vad-dir modelscope model ID --vad-quant True为量化VAD模型,False为非量化VAD模型,默认是True --punc-dir modelscope model ID --punc-quant True为量化PUNC模型,False为非量化PUNC模型,默认是True --itn-dir modelscope model ID --port 服务端监听的端口号,默认为 10095 --decoder-thread-num 服务端启动的推理线程数,默认为 8 --io-thread-num 服务端启动的IO线程数,默认为 1 --certfile ssl的证书文件,默认为:../../../ssl_key/server.crt,如果需要关闭ssl,参数设置为”“ --keyfile ssl的密钥文件,默认为:../../../ssl_key/server.key,如果需要关闭ssl,参数设置为”“ ``` funasr-wss-server同时也支持从本地路径加载模型(本地模型资源准备详见[模型资源准备](#模型资源准备))示例如下: ```shell cd /workspace/FunASR/funasr/runtime/websocket/build/bin ./funasr-wss-server \ --model-dir /workspace/models/damo/speech_paraformer-large_asr_nat-en-16k-common-vocab10020-onnx \ --vad-dir /workspace/models/damo/speech_fsmn_vad_zh-cn-16k-common-onnx \ --punc-dir /workspace/models/damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx \ --decoder-thread-num 32 \ --io-thread-num 8 \ --port 10095 \ --certfile ../../../ssl_key/server.crt \ --keyfile ../../../ssl_key/server.key ``` 命令参数介绍: ```text --model-dir ASR模型路径,默认为:/workspace/models/asr --quantize True为量化ASR模型,False为非量化ASR模型,默认是True --vad-dir VAD模型路径,默认为:/workspace/models/vad --vad-quant True为量化VAD模型,False为非量化VAD模型,默认是True --punc-dir PUNC模型路径,默认为:/workspace/models/punc --punc-quant True为量化PUNC模型,False为非量化PUNC模型,默认是True --itn-dir modelscope model ID --port 服务端监听的端口号,默认为 10095 --decoder-thread-num 服务端启动的推理线程数,默认为 8 --io-thread-num 服务端启动的IO线程数,默认为 1 --certfile ssl的证书文件,默认为:../../../ssl_key/server.crt,如果需要关闭ssl,参数设置为”“ --keyfile ssl的密钥文件,默认为:../../../ssl_key/server.key,如果需要关闭ssl,参数设置为”“ ``` 执行上述指令后,启动离线文件转写服务。如果模型指定为ModelScope中model id,会自动从MoldeScope中下载如下模型: [FSMN-VAD模型](https://www.modelscope.cn/models/damo/speech_fsmn_vad_zh-cn-16k-common-onnx/summary), [Paraformer-lagre模型](https://www.modelscope.cn/models/damo/speech_paraformer-large_asr_nat-en-16k-common-vocab10020-onnx/summary) [CT-Transformer标点预测模型](https://www.modelscope.cn/models/damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx/summary) 如果,您希望部署您finetune后的模型(例如10epoch.pb),需要手动将模型重命名为model.pb,并将原modelscope中模型model.pb替换掉,将路径指定为`model_dir`即可。 ## 如何定制服务部署 FunASR-runtime的代码已开源,如果服务端和客户端不能很好的满足您的需求,您可以根据自己的需求进行进一步的开发: ### c++ 客户端: https://github.com/alibaba-damo-academy/FunASR/tree/main/funasr/runtime/websocket ### python 客户端: https://github.com/alibaba-damo-academy/FunASR/tree/main/funasr/runtime/python/websocket ### 自定义客户端: 如果您想定义自己的client,参考[websocket通信协议](./websocket_protocol_zh.md) ``` ### c++ 服务端: #### VAD ```c++ // VAD模型的使用分为FsmnVadInit和FsmnVadInfer两个步骤: FUNASR_HANDLE vad_hanlde=FsmnVadInit(model_path, thread_num); // 其中:model_path 包含"model-dir"、"quantize",thread_num为onnx线程数; FUNASR_RESULT result=FsmnVadInfer(vad_hanlde, wav_file.c_str(), NULL, 16000); // 其中:vad_hanlde为FunOfflineInit返回值,wav_file为音频路径,sampling_rate为采样率(默认16k) ``` 使用示例详见:https://github.com/alibaba-damo-academy/FunASR/blob/main/funasr/runtime/onnxruntime/bin/funasr-onnx-offline-vad.cpp #### ASR ```text // ASR模型的使用分为FunOfflineInit和FunOfflineInfer两个步骤: FUNASR_HANDLE asr_hanlde=FunOfflineInit(model_path, thread_num); // 其中:model_path 包含"model-dir"、"quantize",thread_num为onnx线程数; FUNASR_RESULT result=FunOfflineInfer(asr_hanlde, wav_file.c_str(), RASR_NONE, NULL, 16000); // 其中:asr_hanlde为FunOfflineInit返回值,wav_file为音频路径,sampling_rate为采样率(默认16k) ``` 使用示例详见:https://github.com/alibaba-damo-academy/FunASR/blob/main/funasr/runtime/onnxruntime/bin/funasr-onnx-offline.cpp #### PUNC ```text // PUNC模型的使用分为CTTransformerInit和CTTransformerInfer两个步骤: FUNASR_HANDLE punc_hanlde=CTTransformerInit(model_path, thread_num); // 其中:model_path 包含"model-dir"、"quantize",thread_num为onnx线程数; FUNASR_RESULT result=CTTransformerInfer(punc_hanlde, txt_str.c_str(), RASR_NONE, NULL); // 其中:punc_hanlde为CTTransformerInit返回值,txt_str为文本 ``` 使用示例详见:https://github.com/alibaba-damo-academy/FunASR/blob/main/funasr/runtime/onnxruntime/bin/funasr-onnx-offline-punc.cpp funasr/runtime/docs/SDK_advanced_guide_offline_zh.md
@@ -26,7 +26,7 @@ registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-cpu-0.2.2 mkdir -p ./funasr-runtime-resources/models sudo docker run -p 10095:10095 -it --privileged=true \ -v ./funasr-runtime-resources/models:/workspace/models \ -v $PWD/funasr-runtime-resources/models:/workspace/models \ registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-cpu-0.2.2 ``` 如果您没有安装docker,可参考[Docker安装](#Docker安装) funasr/runtime/docs/SDK_advanced_guide_online.md
@@ -10,7 +10,7 @@ ```shell sudo docker pull registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-online-cpu-0.1.2 mkdir -p ./funasr-runtime-resources/models sudo docker run -p 10095:10095 -it --privileged=true -v ./funasr-runtime-resources/models:/workspace/models registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-online-cpu-0.1.2 sudo docker run -p 10095:10095 -it --privileged=true -v $PWD/funasr-runtime-resources/models:/workspace/models registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-online-cpu-0.1.2 ``` If you do not have Docker installed, please refer to [Docker Installation](https://alibaba-damo-academy.github.io/FunASR/en/installation/docker.html) funasr/runtime/docs/SDK_advanced_guide_online_zh.md
@@ -15,7 +15,7 @@ registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-online-cpu-0.1.2 mkdir -p ./funasr-runtime-resources/models sudo docker run -p 10095:10095 -it --privileged=true \ -v ./funasr-runtime-resources/models:/workspace/models \ -v $PWD/funasr-runtime-resources/models:/workspace/models \ registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-online-cpu-0.1.2 ``` 如果您没有安装docker,可参考[Docker安装](https://alibaba-damo-academy.github.io/FunASR/en/installation/docker_zh.html) funasr/runtime/docs/SDK_tutorial_en.md
New file @@ -0,0 +1,198 @@ ([简体中文](./SDK_tutorial_en_zh.md)|English) # Highlights **FunASR offline file transcription service 1.0 has been released. Feel free to deploy and experience it!** # FunASR Offline File Transcription Service FunASR provides an offline file transcription service that can be easily deployed on a local or cloud server. The core is the FunASR open-source runtime-SDK. It integrates various capabilities such as speech endpoint detection (VAD) and Paraformer-large speech recognition (ASR) and punctuation restoration (PUNC) released by the speech laboratory of the Damo Academy in the Modelscope community. It has a complete speech recognition chain and can recognize audio or video of tens of hours into punctuated text. Moreover, it supports transcription for hundreds of simultaneous requests. ## Server Configuration Users can choose appropriate server configurations based on their business needs. The recommended configurations are: - Configuration 1: (X86, computing-type) 4-core vCPU, 8GB memory, and a single machine can support about 32 requests. - Configuration 2: (X86, computing-type) 16-core vCPU, 32GB memory, and a single machine can support about 64 requests. - Configuration 3: (X86, computing-type) 64-core vCPU, 128GB memory, and a single machine can support about 200 requests. Detailed performance [report](./benchmark_onnx_cpp.md) Cloud service providers offer a 3-month free trial for new users. Application tutorial ([docs](./aliyun_server_tutorial.md)). ## Quick Start ### Server Startup `Note`: The one-click deployment tool process includes installing Docker, downloading Docker images, and starting the service. If the user wants to start from the FunASR Docker image, please refer to the development guide ([docs](./SDK_advanced_guide_offline.md). Download the deployment tool `funasr-runtime-deploy-offline-cpu-en.sh` ```shell curl -O https://raw.githubusercontent.com/alibaba-damo-academy/FunASR/main/funasr/runtime/deploy_tools/funasr-runtime-deploy-offline-cpu-en.sh; # If there is a network problem, users in mainland China can use the following command: # curl -O https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/shell/funasr-runtime-deploy-offline-cpu-en.sh; ``` Execute the deployment tool and press the Enter key at the prompt to complete the installation and deployment of the server. Currently, the convenient deployment tool only supports Linux environments. For other environments, please refer to the development guide ([docs](./SDK_advanced_guide_offline_en.md)). ```shell sudo bash funasr-runtime-deploy-offline-cpu-en.sh install --workspace /root/funasr-runtime-resources ``` ### Client Testing and Usage After running the above installation instructions, the client testing tool directory samples will be downloaded in the default installation directory /root/funasr-runtime-resources ([download click](https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/sample/funasr_samples.tar.gz)). We take the Python language client as an example to explain that it supports multiple audio format inputs (such as .wav, .pcm, .mp3, etc.), video inputs (.mp4, etc.), and multiple file list wav.scp inputs. For other client versions, please refer to the [documentation](#Detailed-Description-of-Client-Usage). ```shell python3 funasr_wss_client.py --host "127.0.0.1" --port 10095 --mode offline --audio_in "../audio/asr_example.wav" ``` ## Detailed Description of Client Usage After completing the FunASR runtime-SDK service deployment on the server, you can test and use the offline file transcription service through the following steps. Currently, the following programming language client versions are supported: - [Python](#python-client) - [CPP](#cpp-client) - [html](#html-client) - [java](#java-client) For more client version support, please refer to the [development guide](./SDK_advanced_guide_offline_zh.md). ### python-client If you want to run the client directly for testing, you can refer to the following simple instructions, using the Python version as an example: ```shell python3 funasr_wss_client.py --host "127.0.0.1" --port 10095 --mode offline --audio_in "../audio/asr_example.wav" ``` Command parameter instructions: ```text --host is the IP address of the FunASR runtime-SDK service deployment machine, which defaults to the local IP address (127.0.0.1). If the client and the service are not on the same server, it needs to be changed to the deployment machine IP address. --port 10095 deployment port number --mode offline represents offline file transcription --audio_in is the audio file that needs to be transcribed, supporting file paths and file list wav.scp --thread_num sets the number of concurrent sending threads, default is 1 --ssl sets whether to enable SSL certificate verification, default is 1 to enable, and 0 to disable --hotword If am is hotword model, setting hotword: *.txt(one hotword perline) or hotwords seperate by space (could be: 阿里巴巴 达摩院) --use_itn: whether to use itn, the default value is 1 for enabling and 0 for disabling. ``` ### cpp-client After entering the samples/cpp directory, you can test it with CPP. The command is as follows: ```shell ./funasr-wss-client --server-ip 127.0.0.1 --port 10095 --wav-path ../audio/asr_example.wav ``` Command parameter description: ```text --server-ip specifies the IP address of the machine where the FunASR runtime-SDK service is deployed. The default value is the local IP address (127.0.0.1). If the client and the service are not on the same server, the IP address needs to be changed to the IP address of the deployment machine. --port specifies the deployment port number as 10095. --wav-path specifies the audio file to be transcribed, and supports file paths. --thread_num sets the number of concurrent send threads, with a default value of 1. --ssl sets whether to enable SSL certificate verification, with a default value of 1 for enabling and 0 for disabling. --hotword If am is hotword model, setting hotword: *.txt(one hotword perline) or hotwords seperate by space (could be: 阿里巴巴 达摩院) --use-itn: whether to use itn, the default value is 1 for enabling and 0 for disabling. ``` ### html-client To experience it directly, open `html/static/index.html` in your browser. You will see the following page, which supports microphone input and file upload. <img src="images/html.png" width="900"/> ### java-client ```shell FunasrWsClient --host localhost --port 10095 --audio_in ./asr_example.wav --mode offline ``` For more details, please refer to the [docs](../java/readme.md) ## Server Usage Details ### Start the deployed FunASR service If you have restarted the computer or shut down Docker after one-click deployment, you can start the FunASR service directly with the following command. The startup configuration is the same as the last one-click deployment. ```shell sudo bash funasr-runtime-deploy-offline-cpu-en.sh start ``` ### Stop the FunASR service ```shell sudo bash funasr-runtime-deploy-offline-cpu-en.sh stop ``` ### Release the FunASR service Release the deployed FunASR service. ```shell sudo bash funasr-runtime-deploy-offline-cpu-en.sh remove ``` ### Restart the FunASR service Restart the FunASR service with the same configuration as the last one-click deployment. ```shell sudo bash funasr-runtime-deploy-offline-cpu-en.sh restart ``` ### Replace the model and restart the FunASR service Replace the currently used model, and restart the FunASR service. The model must be an ASR/VAD/PUNC model in ModelScope, or a finetuned model from ModelScope. ```shell sudo bash funasr-runtime-deploy-offline-cpu-en.sh update [--asr_model | --vad_model | --punc_model] <model_id or local model path> e.g sudo bash funasr-runtime-deploy-offline-cpu-en.sh update --asr_model damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch ``` ### Update parameters and restart the FunASR service Update the configured parameters and restart the FunASR service to take effect. The parameters that can be updated include the host and Docker port numbers, as well as the number of inference and IO threads. ```shell sudo bash funasr-runtime-deploy-offline-cpu-en.sh update [--host_port | --docker_port] <port number> sudo bash funasr-runtime-deploy-offline-cpu-en.sh update [--decode_thread_num | --io_thread_num] <the number of threads> sudo bash funasr-runtime-deploy-offline-cpu-en.sh update [--workspace] <workspace in local> sudo bash funasr-runtime-deploy-offline-cpu-en.sh update [--ssl] <0: close SSL; 1: open SSL, default:1> e.g sudo bash funasr-runtime-deploy-offline-cpu-en.sh update --decode_thread_num 32 sudo bash funasr-runtime-deploy-offline-cpu-en.sh update --workspace /root/funasr-runtime-resources ``` ### Set SSL SSL verification is enabled by default. If you need to disable it, you can set it when starting. ```shell sudo bash funasr-runtime-deploy-offline-cpu-en.sh update --ssl 0 ``` ## Contact Us If you encounter any problems during use, please join our user group for feedback. | DingDing Group | Wechat | |:----------------------------------------------------------------------------:|:--------------------------------------------------------------:| | <div align="left"><img src="../../../docs/images/dingding.jpg" width="250"/> | <img src="../../../docs/images/wechat.png" width="232"/></div> | funasr/runtime/docs/SDK_tutorial_en_zh.md
New file @@ -0,0 +1,204 @@ (简体中文|[English](./SDK_tutorial_en.md)) # FunASR英文离线文件转写服务便捷部署教程 FunASR提供可便捷本地或者云端服务器部署的离线文件转写服务,内核为FunASR已开源runtime-SDK。 集成了达摩院语音实验室在Modelscope社区开源的语音端点检测(VAD)、Paraformer-large语音识别(ASR)、标点恢复(PUNC) 等相关能力,拥有完整的语音识别链路,可以将几十个小时的音频或视频识别成带标点的文字,而且支持上百路请求同时进行转写。 # 发布日志 **FunASR英文离线文件转写服务1.0已发布,欢迎部署体验[快速上手](#快速上手)** ## 服务器配置 用户可以根据自己的业务需求,选择合适的服务器配置,推荐配置为: - 配置1: (X86,计算型),4核vCPU,内存8G,单机可以支持大约32路的请求 - 配置2: (X86,计算型),16核vCPU,内存32G,单机可以支持大约64路的请求 - 配置3: (X86,计算型),64核vCPU,内存128G,单机可以支持大约200路的请求 详细性能测试报告([点击此处](./benchmark_onnx_cpp.md)) 云服务厂商,针对新用户,有3个月免费试用活动,申请教程([点击此处](https://github.com/alibaba-damo-academy/FunASR/blob/main/funasr/runtime/docs/aliyun_server_tutorial.md)) ## 快速上手 ### 服务端启动 `注意`:一键部署工具,过程分为:安装docker、下载docker镜像、启动服务。如果用户希望直接从FunASR docker镜像启动,可以参考开发指南([点击此处](./SDK_advanced_guide_offline_en_zh.md)) 下载部署工具`funasr-runtime-deploy-offline-cpu-en.sh` ```shell curl -O https://raw.githubusercontent.com/alibaba-damo-academy/FunASR/main/funasr/runtime/deploy_tools/funasr-runtime-deploy-offline-cpu-en.sh; # 如遇到网络问题,中国大陆用户,可以使用下面的命令: # curl -O https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/shell/funasr-runtime-deploy-offline-cpu-en.sh; ``` 执行部署工具,在提示处输入回车键即可完成服务端安装与部署。目前便捷部署工具暂时仅支持Linux环境,其他环境部署参考开发指南([点击此处](./SDK_advanced_guide_offline_zh.md)) ```shell sudo bash funasr-runtime-deploy-offline-cpu-en.sh install --workspace ./funasr-runtime-resources ``` ### 客户端测试与使用 运行上面安装指令后,会在/root/funasr-runtime-resources(默认安装目录)中下载客户端测试工具目录samples(手动下载,[点击此处](https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/sample/funasr_samples.tar.gz)), 我们以Python语言客户端为例,进行说明,支持多种音频格式输入(.wav, .pcm, .mp3等),也支持视频输入(.mp4等),以及多文件列表wav.scp输入,其他版本客户端请参考文档([点击此处](#客户端用法详解)) ```shell python3 funasr_wss_client.py --host "127.0.0.1" --port 10095 --mode offline --audio_in "../audio/asr_example.wav" ``` ## 客户端用法详解 在服务器上完成FunASR服务部署以后,可以通过如下的步骤来测试和使用离线文件转写服务。 目前分别支持以下几种编程语言客户端 - [Python](#python-client) - [CPP](#cpp-client) - [html](#html-client) - [java](#java-client) 更多版本客户端支持请参考[websocket/grpc协议](./websocket_protocol_zh.md) ### python-client 若想直接运行client进行测试,可参考如下简易说明,以python版本为例: ```shell python3 funasr_wss_client.py --host "127.0.0.1" --port 10095 --mode offline --audio_in "../audio/asr_example.wav" ``` 命令参数说明: ```text --host 为FunASR runtime-SDK服务部署机器ip,默认为本机ip(127.0.0.1),如果client与服务不在同一台服务器, 需要改为部署机器ip --port 10095 部署端口号 --mode offline表示离线文件转写 --audio_in 需要进行转写的音频文件,支持文件路径,文件列表wav.scp --thread_num 设置并发发送线程数,默认为1 --ssl 设置是否开启ssl证书校验,默认1开启,设置为0关闭 --hotword 如果模型为热词模型,可以设置热词: *.txt(每行一个热词) 或者空格分隔的热词字符串 (阿里巴巴 达摩院) --use_itn 设置是否使用itn,默认1开启,设置为0关闭 ``` ### cpp-client 进入samples/cpp目录后,可以用cpp进行测试,指令如下: ```shell ./funasr-wss-client --server-ip 127.0.0.1 --port 10095 --wav-path ../audio/asr_example.wav ``` 命令参数说明: ```text --server-ip 为FunASR runtime-SDK服务部署机器ip,默认为本机ip(127.0.0.1),如果client与服务不在同一台服务器, 需要改为部署机器ip --port 10095 部署端口号 --wav-path 需要进行转写的音频文件,支持文件路径 --thread_num 设置并发发送线程数,默认为1 --ssl 设置是否开启ssl证书校验,默认1开启,设置为0关闭 --hotword 如果模型为热词模型,可以设置热词: *.txt(每行一个热词) 或者空格分隔的热词字符串 (阿里巴巴 达摩院) --use-itn 设置是否使用itn,默认1开启,设置为0关闭 ``` ### html-client 在浏览器中打开 html/static/index.html,即可出现如下页面,支持麦克风输入与文件上传,直接进行体验 <img src="images/html.png" width="900"/> ### java-client ```shell FunasrWsClient --host localhost --port 10095 --audio_in ./asr_example.wav --mode offline ``` 详细可以参考文档([点击此处](../java/readme.md)) ## 服务端用法详解 ### 启动已经部署过的FunASR服务 一键部署后若出现重启电脑等关闭Docker的动作,可通过如下命令直接启动FunASR服务,启动配置为上次一键部署的设置。 ```shell sudo bash funasr-runtime-deploy-offline-cpu-en.sh start ``` ### 关闭FunASR服务 ```shell sudo bash funasr-runtime-deploy-offline-cpu-en.sh stop ``` ### 释放FunASR服务 释放已经部署的FunASR服务。 ```shell sudo bash funasr-runtime-deploy-offline-cpu-en.sh remove ``` ### 重启FunASR服务 根据上次一键部署的设置重启启动FunASR服务。 ```shell sudo bash funasr-runtime-deploy-offline-cpu-en.sh restart ``` ### 替换模型并重启FunASR服务 替换正在使用的模型,并重新启动FunASR服务。模型需为ModelScope中的ASR/VAD/PUNC模型,或者从ModelScope中模型finetune后的模型。 ```shell sudo bash funasr-runtime-deploy-offline-cpu-en.sh update [--asr_model | --vad_model | --punc_model] <model_id or local model path> e.g sudo bash funasr-runtime-deploy-offline-cpu-en.sh update --asr_model damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch ``` ### 更新参数并重启FunASR服务 更新已配置参数,并重新启动FunASR服务生效。可更新参数包括宿主机和Docker的端口号,以及推理和IO的线程数量。 ```shell sudo bash funasr-runtime-deploy-offline-cpu-en.sh update [--host_port | --docker_port] <port number> sudo bash funasr-runtime-deploy-offline-cpu-en.sh update [--decode_thread_num | --io_thread_num] <the number of threads> sudo bash funasr-runtime-deploy-offline-cpu-en.sh update [--workspace] <workspace in local> sudo bash funasr-runtime-deploy-offline-cpu-en.sh update [--ssl] <0: close SSL; 1: open SSL, default:1> e.g sudo bash funasr-runtime-deploy-offline-cpu-en.sh update --decode_thread_num 32 sudo bash funasr-runtime-deploy-offline-cpu-en.sh update --workspace /root/funasr-runtime-resources ``` ### 关闭SSL证书 ```shell sudo bash funasr-runtime-deploy-offline-cpu-en.sh update --ssl 0 ``` ## 联系我们 在您使用过程中,如果遇到问题,欢迎加入用户群进行反馈 | 钉钉用户群 | 微信 | |:----------------------------------------------------------------------------:|:-----------------------------------------------------:| | <div align="left"><img src="../../../docs/images/dingding.jpg" width="250"/> | <img src="../../../docs/images/wechat.png" width="232"/></div> | ## 视频demo [点击此处]() funasr/runtime/docs/docker_offline_cpu_en_lists
New file @@ -0,0 +1,8 @@ DOCKER: funasr-runtime-sdk-en-cpu-0.1.0 DEFAULT_ASR_MODEL: damo/speech_paraformer-large_asr_nat-en-16k-common-vocab10020-onnx DEFAULT_VAD_MODEL: damo/speech_fsmn_vad_zh-cn-16k-common-onnx DEFAULT_PUNC_MODEL: damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx funasr/runtime/onnxruntime/include/funasrruntime.h
@@ -18,10 +18,6 @@ #define FUNASR_CALLBCK_PREFIX __stdcall #endif #ifdef __cplusplus extern "C" { #endif typedef void* FUNASR_HANDLE; typedef void* FUNASR_RESULT; @@ -122,7 +118,4 @@ _FUNASRAPI void FunTpassUninit(FUNASR_HANDLE handle); _FUNASRAPI void FunTpassOnlineUninit(FUNASR_HANDLE handle); #ifdef __cplusplus } #endif funasr/runtime/onnxruntime/src/audio.cpp
@@ -9,6 +9,9 @@ #include "audio.h" #include "precomp.h" #ifdef _MSC_VER #pragma warning(disable:4996) #endif #if defined(__APPLE__) #include <string.h> @@ -423,7 +426,7 @@ return false; #else // from buf char* buf_copy = (char *)malloc(n_file_len); void* buf_copy = av_malloc(n_file_len); memcpy(buf_copy, buf, n_file_len); AVIOContext* avio_ctx = avio_alloc_context( funasr/runtime/onnxruntime/src/commonfunc.h
@@ -1,29 +1,34 @@ #pragma once #include <algorithm> #ifdef _WIN32 #include <codecvt> #endif namespace funasr { typedef struct { std::string msg=""; std::string stamp=""; std::string tpass_msg=""; float snippet_time=0; std::string msg; std::string stamp; std::string tpass_msg; float snippet_time; }FUNASR_RECOG_RESULT; typedef struct { std::vector<std::vector<int>>* segments; float snippet_time=0; float snippet_time; }FUNASR_VAD_RESULT; typedef struct { string msg=""; string msg; vector<string> arr_cache; }FUNASR_PUNC_RESULT; #ifdef _WIN32 #include <codecvt> #define ORTSTRING(str) StrToWstr(str) #define ORTCHAR(str) StrToWstr(str).c_str() inline std::wstring String2wstring(const std::string& str, const std::string& locale) { @@ -39,8 +44,15 @@ } #else #define ORTSTRING(str) str #define ORTCHAR(str) str #endif inline void GetInputName(Ort::Session* session, string& inputName,int nIndex=0) { size_t numInputNodes = session->GetInputCount(); if (numInputNodes > 0) { funasr/runtime/onnxruntime/src/ct-transformer-online.cpp
@@ -17,7 +17,7 @@ session_options.DisableCpuMemArena(); try{ m_session = std::make_unique<Ort::Session>(env_, punc_model.c_str(), session_options); m_session = std::make_unique<Ort::Session>(env_, ORTSTRING(punc_model).c_str(), session_options); LOG(INFO) << "Successfully load model from " << punc_model; } catch (std::exception const &e) { @@ -74,8 +74,8 @@ for (size_t i = 0; i < InputData.size(); i += TOKEN_LEN) { nDiff = (i + TOKEN_LEN) < InputData.size() ? (0) : (i + TOKEN_LEN - InputData.size()); vector<int32_t> InputIDs(InputData.begin() + i, InputData.begin() + i + TOKEN_LEN - nDiff); vector<string> InputStr(strOut.begin() + i, strOut.begin() + i + TOKEN_LEN - nDiff); vector<int32_t> InputIDs(InputData.begin() + i, InputData.begin() + i + (TOKEN_LEN - nDiff)); vector<string> InputStr(strOut.begin() + i, strOut.begin() + i + (TOKEN_LEN - nDiff)); InputIDs.insert(InputIDs.begin(), RemainIDs.begin(), RemainIDs.end()); // RemainIDs+InputIDs; InputStr.insert(InputStr.begin(), RemainStr.begin(), RemainStr.end()); // RemainStr+InputStr; @@ -102,10 +102,10 @@ nSentEnd = nLastCommaIndex; Punction[nSentEnd] = PERIOD_INDEX; } RemainStr.assign(InputStr.begin() + nSentEnd + 1, InputStr.end()); RemainIDs.assign(InputIDs.begin() + nSentEnd + 1, InputIDs.end()); InputStr.assign(InputStr.begin(), InputStr.begin() + nSentEnd + 1); // minit_sentence Punction.assign(Punction.begin(), Punction.begin() + nSentEnd + 1); RemainStr.assign(InputStr.begin() + (nSentEnd + 1), InputStr.end()); RemainIDs.assign(InputIDs.begin() + (nSentEnd + 1), InputIDs.end()); InputStr.assign(InputStr.begin(), InputStr.begin() + (nSentEnd + 1)); // minit_sentence Punction.assign(Punction.begin(), Punction.begin() + (nSentEnd + 1)); } for (auto& item : Punction) @@ -149,7 +149,7 @@ break; } } arr_cache.assign(sentence_words_list.begin() + nSentEnd + 1, sentence_words_list.end()); arr_cache.assign(sentence_words_list.begin() + (nSentEnd + 1), sentence_words_list.end()); if (sentenceOut.size() > 0 && m_tokenizer.IsPunc(sentenceOut[sentenceOut.size() - 1])) { funasr/runtime/onnxruntime/src/ct-transformer.cpp
@@ -17,7 +17,7 @@ session_options.DisableCpuMemArena(); try{ m_session = std::make_unique<Ort::Session>(env_, punc_model.c_str(), session_options); m_session = std::make_unique<Ort::Session>(env_, ORTSTRING(punc_model).c_str(), session_options); LOG(INFO) << "Successfully load model from " << punc_model; } catch (std::exception const &e) { @@ -66,8 +66,8 @@ for (size_t i = 0; i < InputData.size(); i += TOKEN_LEN) { nDiff = (i + TOKEN_LEN) < InputData.size() ? (0) : (i + TOKEN_LEN - InputData.size()); vector<int32_t> InputIDs(InputData.begin() + i, InputData.begin() + i + TOKEN_LEN - nDiff); vector<string> InputStr(strOut.begin() + i, strOut.begin() + i + TOKEN_LEN - nDiff); vector<int32_t> InputIDs(InputData.begin() + i, InputData.begin() + i + (TOKEN_LEN - nDiff)); vector<string> InputStr(strOut.begin() + i, strOut.begin() + i + (TOKEN_LEN - nDiff)); InputIDs.insert(InputIDs.begin(), RemainIDs.begin(), RemainIDs.end()); // RemainIDs+InputIDs; InputStr.insert(InputStr.begin(), RemainStr.begin(), RemainStr.end()); // RemainStr+InputStr; @@ -94,10 +94,10 @@ nSentEnd = nLastCommaIndex; Punction[nSentEnd] = PERIOD_INDEX; } RemainStr.assign(InputStr.begin() + nSentEnd + 1, InputStr.end()); RemainIDs.assign(InputIDs.begin() + nSentEnd + 1, InputIDs.end()); InputStr.assign(InputStr.begin(), InputStr.begin() + nSentEnd + 1); // minit_sentence Punction.assign(Punction.begin(), Punction.begin() + nSentEnd + 1); RemainStr.assign(InputStr.begin() + (nSentEnd + 1), InputStr.end()); RemainIDs.assign(InputIDs.begin() + (nSentEnd + 1), InputIDs.end()); InputStr.assign(InputStr.begin(), InputStr.begin() + (nSentEnd + 1)); // minit_sentence Punction.assign(Punction.begin(), Punction.begin() + (nSentEnd + 1)); } NewPunctuation.insert(NewPunctuation.end(), Punction.begin(), Punction.end()); funasr/runtime/onnxruntime/src/fsmn-vad.cpp
@@ -54,7 +54,7 @@ void FsmnVad::ReadModel(const char* vad_model) { try { vad_session_ = std::make_shared<Ort::Session>( env_, vad_model, session_options_); env_, ORTCHAR(vad_model), session_options_); LOG(INFO) << "Successfully load model from " << vad_model; } catch (std::exception const &e) { LOG(ERROR) << "Error when load vad onnx model: " << e.what(); funasr/runtime/onnxruntime/src/funasrruntime.cpp
@@ -1,9 +1,6 @@ #include "precomp.h" #include <vector> #ifdef __cplusplus extern "C" { #endif // APIs for Init _FUNASRAPI FUNASR_HANDLE FunASRInit(std::map<std::string, std::string>& model_path, int thread_num, ASR_TYPE type) @@ -257,11 +254,15 @@ int n_total = audio.GetQueueSize(); float start_time = 0.0; std::string cur_stamp = "["; std::string lang = (offline_stream->asr_handle)->GetLang(); while (audio.Fetch(buff, len, flag, start_time) > 0) { string msg = (offline_stream->asr_handle)->Forward(buff, len, true, hw_emb); std::vector<std::string> msg_vec = funasr::split(msg, '|'); if(msg_vec.size()==0){ continue; } if(lang == "en-bpe" and p_result->msg != ""){ p_result->msg += " "; } p_result->msg += msg_vec[0]; //timestamp @@ -282,7 +283,6 @@ p_result->stamp += cur_stamp + "]"; } if(offline_stream->UsePunc()){ string lang = (offline_stream->asr_handle)->GetLang(); string punc_res = (offline_stream->punc_handle)->AddPunc((p_result->msg).c_str(), lang); p_result->msg = punc_res; } @@ -338,11 +338,15 @@ int n_total = audio.GetQueueSize(); float start_time = 0.0; std::string cur_stamp = "["; std::string lang = (offline_stream->asr_handle)->GetLang(); while (audio.Fetch(buff, len, flag, start_time) > 0) { string msg = (offline_stream->asr_handle)->Forward(buff, len, true, hw_emb); std::vector<std::string> msg_vec = funasr::split(msg, '|'); if(msg_vec.size()==0){ continue; } if(lang == "en-bpe" and p_result->msg != ""){ p_result->msg += " "; } p_result->msg += msg_vec[0]; //timestamp @@ -364,7 +368,6 @@ p_result->stamp += cur_stamp + "]"; } if(offline_stream->UsePunc()){ string lang = (offline_stream->asr_handle)->GetLang(); string punc_res = (offline_stream->punc_handle)->AddPunc((p_result->msg).c_str(), lang); p_result->msg = punc_res; } @@ -688,8 +691,4 @@ delete tpass_online_stream; } #ifdef __cplusplus } #endif funasr/runtime/onnxruntime/src/offline-stream.cpp
@@ -1,5 +1,4 @@ #include "precomp.h" #include <unistd.h> namespace funasr { OfflineStream::OfflineStream(std::map<std::string, std::string>& model_path, int thread_num) funasr/runtime/onnxruntime/src/paraformer.cpp
@@ -37,7 +37,7 @@ session_options_.DisableCpuMemArena(); try { m_session_ = std::make_unique<Ort::Session>(env_, am_model.c_str(), session_options_); m_session_ = std::make_unique<Ort::Session>(env_, ORTSTRING(am_model).c_str(), session_options_); LOG(INFO) << "Successfully load model from " << am_model; } catch (std::exception const &e) { LOG(ERROR) << "Error when load am onnx model: " << e.what(); @@ -90,7 +90,7 @@ session_options_.DisableCpuMemArena(); try { encoder_session_ = std::make_unique<Ort::Session>(env_, en_model.c_str(), session_options_); encoder_session_ = std::make_unique<Ort::Session>(env_, ORTSTRING(en_model).c_str(), session_options_); LOG(INFO) << "Successfully load model from " << en_model; } catch (std::exception const &e) { LOG(ERROR) << "Error when load am encoder model: " << e.what(); @@ -98,7 +98,7 @@ } try { decoder_session_ = std::make_unique<Ort::Session>(env_, de_model.c_str(), session_options_); decoder_session_ = std::make_unique<Ort::Session>(env_, ORTSTRING(de_model).c_str(), session_options_); LOG(INFO) << "Successfully load model from " << de_model; } catch (std::exception const &e) { LOG(ERROR) << "Error when load am decoder model: " << e.what(); @@ -153,7 +153,7 @@ // offline try { m_session_ = std::make_unique<Ort::Session>(env_, am_model.c_str(), session_options_); m_session_ = std::make_unique<Ort::Session>(env_, ORTSTRING(am_model).c_str(), session_options_); LOG(INFO) << "Successfully load model from " << am_model; } catch (std::exception const &e) { LOG(ERROR) << "Error when load am onnx model: " << e.what(); @@ -250,7 +250,7 @@ hw_session_options.DisableCpuMemArena(); try { hw_m_session = std::make_unique<Ort::Session>(hw_env_, hw_model.c_str(), hw_session_options); hw_m_session = std::make_unique<Ort::Session>(hw_env_, ORTSTRING(hw_model).c_str(), hw_session_options); LOG(INFO) << "Successfully load model from " << hw_model; } catch (std::exception const &e) { LOG(ERROR) << "Error when load hw compiler onnx model: " << e.what(); funasr/runtime/onnxruntime/src/precomp.h
@@ -17,6 +17,25 @@ #include <numeric> #include <cstring> #ifdef _WIN32 #include<io.h> #ifndef R_OK #define R_OK 4 #endif #ifndef W_OK #define W_OK 2 #endif #ifndef X_OK #define X_OK 0 #endif #ifndef F_OK #define F_OK 0 #endif #define access _access #else #include <unistd.h> #endif using namespace std; // third part #if defined(__APPLE__) @@ -33,6 +52,8 @@ // mine #include <glog/logging.h> #include "common-struct.h" #include "com-define.h" #include "commonfunc.h" funasr/runtime/onnxruntime/src/tpass-online-stream.cpp
@@ -1,5 +1,4 @@ #include "precomp.h" #include <unistd.h> namespace funasr { TpassOnlineStream::TpassOnlineStream(TpassStream* tpass_stream, std::vector<int> chunk_size){ funasr/runtime/onnxruntime/src/tpass-stream.cpp
@@ -1,5 +1,4 @@ #include "precomp.h" #include <unistd.h> namespace funasr { TpassStream::TpassStream(std::map<std::string, std::string>& model_path, int thread_num) funasr/runtime/readme.md
@@ -6,9 +6,33 @@ - File transcription service, Mandarin, CPU version, done - The real-time transcription service, Mandarin (CPU), done - File transcription service, English, CPU version, done - File transcription service, Mandarin, GPU version, in progress - File transcription service, English, in progress - and more. ## File Transcription Service, English (CPU) Currently, the FunASR runtime-SDK supports the deployment of file transcription service, English (CPU version), with a complete speech recognition chain that can transcribe tens of hours of audio into punctuated text, and supports recognition for more than a hundred concurrent streams. To meet the needs of different users, we have prepared different tutorials with text and images for both novice and advanced developers. ### Technical Principles The technical principles and documentation behind FunASR explain the underlying technology, recognition accuracy, computational efficiency, and core advantages of the framework, including convenience, high precision, high efficiency, and support for long audio chains. For detailed information, please refer to the documentation available by [docs](https://mp.weixin.qq.com/s/DHQwbgdBWcda0w_L60iUww). ### Deployment Tutorial The documentation mainly targets novice users who have no need for modifications or customization. It supports downloading model deployments from modelscope and also supports deploying models that users have fine-tuned. For detailed tutorials, please refer to [docs](docs/SDK_tutorial_en.md). ### Advanced Development Guide The documentation mainly targets advanced developers who require modifications and customization of the service. It supports downloading model deployments from modelscope and also supports deploying models that users have fine-tuned. For detailed information, please refer to the documentation available by [docs](./docs/SDK_advanced_guide_offline_en.md) ### latest version & image ID | image version | image ID | INFO | |------------------------------|-----|------| | funasr-runtime-sdk-en-cpu-0.1.0 | 4ce696fe9ba5 | | ## The real-time transcription service, Mandarin (CPU) @@ -36,13 +60,13 @@ ## File Transcription Service, Mandarin (CPU) Currently, the FunASR runtime-SDK-0.0.1 version supports the deployment of file transcription service, Mandarin (CPU version), with a complete speech recognition chain that can transcribe tens of hours of audio into punctuated text, and supports recognition for more than a hundred concurrent streams. Currently, the FunASR runtime-SDK supports the deployment of file transcription service, Mandarin (CPU version), with a complete speech recognition chain that can transcribe tens of hours of audio into punctuated text, and supports recognition for more than a hundred concurrent streams. To meet the needs of different users, we have prepared different tutorials with text and images for both novice and advanced developers. ### Technical Principles The technical principles and documentation behind FunASR explain the underlying technology, recognition accuracy, computational efficiency, and core advantages of the framework, including convenience, high precision, high efficiency, and support for long audio chains. For detailed information, please refer to the documentation available by [docs](https://mp.weixin.qq.com/s?__biz=MzA3MTQ0NTUyMw==&tempkey=MTIyNF84d05USjMxSEpPdk5GZXBJUFNJNzY0bU1DTkxhV19mcWY4MTNWQTJSYXhUaFgxOWFHZTZKR0JzWC1JRmRCdUxCX2NoQXg0TzFpNmVJX2R1WjdrcC02N2FEcUc3MDhzVVhpNWQ5clU4QUdqNFdkdjFYb18xRjlZMmc5c3RDOTl0U0NiRkJLb05ZZ0RmRlVkVjFCZnpXNWFBVlRhbXVtdWs4bUMwSHZnfn4%3D&chksm=1f2c3254285bbb42bc8f76a82e9c5211518a0bb1ff8c357d085c1b78f675ef2311f3be6e282c#rd). The technical principles and documentation behind FunASR explain the underlying technology, recognition accuracy, computational efficiency, and core advantages of the framework, including convenience, high precision, high efficiency, and support for long audio chains. For detailed information, please refer to the documentation available by [docs](https://mp.weixin.qq.com/s/DHQwbgdBWcda0w_L60iUww). ### Deployment Tutorial funasr/runtime/readme_cn.md
@@ -7,10 +7,34 @@ - 中文离线文件转写服务(CPU版本),已完成 - 中文流式语音识别服务(CPU版本),已完成 - 英文离线文件转写服务(CPU版本),已完成 - 中文离线文件转写服务(GPU版本),进行中 - 英文离线转写服务,进行中 - 更多支持中 ## 英文离线文件转写服务(CPU版本) 英文离线文件转写服务部署(CPU版本),拥有完整的语音识别链路,可以将几十个小时的长音频与视频识别成带标点的文字,而且支持上百路请求同时进行转写。 为了支持不同用户的需求,针对不同场景,准备了不同的图文教程: ### 便捷部署教程 适用场景为,对服务部署SDK无修改需求,部署模型来自于ModelScope,或者用户finetune,详细教程参考([点击此处](./docs/SDK_tutorial_en_zh.md)) ### 开发指南 适用场景为,对服务部署SDK有修改需求,部署模型来自于ModelScope,或者用户finetune,详细文档参考([点击此处](./docs/SDK_advanced_guide_offline_en_zh.md)) ### 技术原理揭秘 文档介绍了背后技术原理,识别准确率,计算效率等,以及核心优势介绍:便捷、高精度、高效率、长音频链路,详细文档参考([点击此处](https://mp.weixin.qq.com/s/DHQwbgdBWcda0w_L60iUww)) ### 最新版本及image ID | image version | image ID | INFO | |------------------------------|-----|------| | funasr-runtime-sdk-en-cpu-0.1.0 | 4ce696fe9ba5 | | ## 中文实时语音听写服务(CPU版本) FunASR实时语音听写服务软件包,既可以实时地进行语音转文字,而且能够在说话句尾用高精度的转写文字修正输出,输出文字带有标点,支持高并发多路请求。