The Voice of artificial intelligence

Source: Internet
Author: User

The following technologies are relying on the Baidu big guy to provide interface operation! The calling interface language is Python

One, download
Pip Install Baidu-aip
Second, speech synthesis

According to the Baidu language synthesis official website, calls can:

#!/usr/bin/env python#-*-Coding:utf8-*- fromAipImportAipspeech"""your APPID AK SK"" " # After registering your Baidu account, create an app to get this dataapp_id="14446029"  Api_key="ferct9kmokugdpbzqdqhqb7v"Secret_key='EXTB37XV1LUBXB8D5FZZNLLJLHNC7VMX'Client=Aipspeech (app_id, Api_key, secret_key) text="What's your name?"Res= Client.synthesis (text, options={    "Vol.": 8,  #     "Pit": 6,    "SPD": 5,    "per": 4})if  notisinstance (res, dict): With open ('Audio.mp3','WB') as F:f.write (res)

Configuration parameters See: Http://ai.baidu.com/docs/#/TTS-Online-Python-SDK/top

This way we generate the ' audio '. mp3 file is the recognized language!

Third, language recognition

At present, Baidu supports the language format: the original PCM recording parameters must conform to the 8k/16k sampling rate, 16bit bit depth, mono, supported by the format: PCM (not compressed), WAV (uncompressed, PCM code), AMR (compressed format) (Baidu said);

In fact, Baidu can accurately identify the voice format only pcm!!!

Then we need to convert our voice format to PCM format! Use this tool to complete the audio in any format!

FFmpeg System Tools: https://pan.baidu.com/s/1jonSAa_TG2XuaJEy3iTmHg Password: W6HK

After the download, unzip, and then configure the environment variables, you can use it! Use the command to see the code below!

#!/usr/bin/env python#-*-coding:utf-8-*-ImportOS fromAipImportAipspeech"""your APPID AK SK"""app_id="14446029"Api_key="ferct9kmokugdpbzqdqhqb7v"Secret_key='EXTB37XV1LUBXB8D5FZZNLLJLHNC7VMX'Client=Aipspeech (app_id, Api_key, Secret_key)defget_file_content (file_path): Cmd_str= f"Ffmpeg-y-i {file_path}-acodec pcm_s16le-f s16le-ac 1-ar 16000 {file_path}.pcm"# for converting our voice formatsOs.system (CMD_STR) with open (f"{FILE_PATH}.PCM",'RB') as FP:returnFp.read () Res= Client.asr (Speech=get_file_content ("2.m4a"), options={    "Dev_pid": 1536,})Print(RES)Print(Res.get ("result") [0])

Parameter configuration see: Http://ai.baidu.com/docs/#/ASR-Online-Python-SDK/top

Four, natural language processing (NLP)

See: Http://ai.baidu.com/docs/#/NLP-Python-SDK/top

 fromAipImportAIPNLP"""your APPID AK SK"""app_id="14446029"Api_key="ferct9kmokugdpbzqdqhqb7v"Secret_key='EXTB37XV1LUBXB8D5FZZNLLJLHNC7VMX'nip_client=AIPNLP (app_id, Api_key, Secret_key)defnip_handle (text):if nip_client.simnet("What's your name?", text). Get ("score") >= 0.72:#used to return two text similarity, greater than 72% can be considered, 2 meaning basically the same!         return "My name is your little cutie."    returnGoto_tuling (Text,"Xipangzi")

The Voice of artificial intelligence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.