示例#1
0
def text_to_speech(content):
    client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)

    result = client.synthesis(content, 'zh', 1, {
        'vol': 5,
    })

    if not isinstance(result, dict):
        with open('synthesis.wav', 'wb') as f:
            f.write(result)
示例#2
0
def str_to_mp3(string):
    aipSpeech = AipSpeech(APP_ID, API_KEY, SECRET_KEY)

    result = aipSpeech.synthesis(string, 'zh', 1, {
        'vol': 5,
        'per': 5,
    })

    # 识别正确返回语音二进制 错误则返回dict 参照下面错误码
    if not isinstance(result, dict):
        with open('./bgm/regular.mp3', 'wb') as f:
            f.write(result)
        os.system("sudo mpg123 ./bgm/regular.mp3")
示例#3
0
def generate_mp3(str, name):
    #str 传入的语句
    #name 保存后的文件名

    aipSpeech = AipSpeech(APP_ID, API_KEY, SECRET_KEY)

    result = aipSpeech.synthesis(str, 'zh', 1, {
        'vol': 5,
        'per': 5,
    })

    # 识别正确返回语音二进制 错误则返回dict 参照下面错误码
    if not isinstance(result, dict):
        filename = './bgm/' + 'name' + '.mp3'
        with open(filename, 'wb') as f:
            f.write(result)
示例#4
0
 def __init__(self, channel=0, supress_error=True):
     with ignore_stderr(enable=supress_error):
         self.pyaudio = pyaudio.PyAudio()
     self.channels = None
     self.channel = channel
     self.device_index = None
     self.rate = 16000
     self.bitwidth = 2
     self.bitdepth = 16
     ####find device####
     count = self.pyaudio.get_device_count()
     for i in range(count):
         info = self.pyaudio.get_device_info_by_index(i)
         name = info["name"].encode("utf-8")
         chan = info["maxInputChannels"]
         if name.lower().find("respeaker") >= 0:
             self.channels = chan
             self.device_index = i
             break
     if self.device_index is None:
         info = self.pyaudio.get_default_input_device_info()
         self.channels = info["maxInputChannels"]
         self.device_index = info["index"]
     self.channel = min(self.channels - 1, max(0, self.channel))
     self.stream = self.pyaudio.open(
         rate=self.rate,
         format=self.pyaudio.get_format_from_width(self.bitwidth),
         channels=1,
         input=True,
         input_device_index=self.device_index,
     )
     self.aipSpeech = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
     self.baidu = BaiduVoiceApi(appkey=API_KEY, secretkey=SECRET_KEY)
示例#5
0
def parse():
    client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)

    def get_file_content(filePath):
        with open(filePath, 'rb') as fp:
            return fp.read()

    text = client.asr(get_file_content('output.wav'), 'wav', 16000, {
        'dev_pid': 1537,
    })
    print text
    try:
        results = text["result"]
    except:
        results = False
    voice_parse = "".join(results)
    return results
示例#6
0
GPIO.output(13, GPIO.LOW)

p = pyaudio.PyAudio()
stream = p.open(
    rate=RESPEAKER_RATE,
    format=p.get_format_from_width(RESPEAKER_WIDTH),
    channels=RESPEAKER_CHANNELS,
    input=True,
    start=False,
)

APP_ID = ''
API_KEY = ''
SECRET_KEY = ''

aipSpeech = AipSpeech(APP_ID, API_KEY, SECRET_KEY)

baidu = BaiduVoiceApi(appkey=API_KEY, secretkey=SECRET_KEY)


def generator_list(list):
    for l in list:
        yield l


def record():
    stream.start_stream()
    print("* recording")
    frames = []
    for i in range(0, int(RESPEAKER_RATE / CHUNK * RECORD_SECONDS)):
        data = stream.read(CHUNK)
示例#7
0
#coding:utf-8

from aip.speech import AipSpeech
import os

APP_ID = '16886339'
API_KEY = 'Ly0TST3N8Y7PA7pLrrou1PZX'
SECRET_KEY = 'O4BphHmbRrwL4K7jBIdHD9cuzVMWAKmg'

aipSpeech = AipSpeech(APP_ID, API_KEY, SECRET_KEY)

#string = '现在温度是{}摄氏度'.format(27.0)
string = '我没听懂,能再说一次吗'

result = aipSpeech.synthesis(string, 'zh', 1, {
    'vol': 5,
    'per': 5,
})

# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
if not isinstance(result, dict):
    with open('./bgm/disunderstand.mp3', 'wb') as f:
        f.write(result)
    os.system("sudo mpg123 ./bgm/disunderstand.mp3")
示例#8
0
    SpacerComponent, ButtonComponent, SeparatorComponent, ImageComponent,
    LocationMessage, LocationSendMessage, AudioMessage)
from linebot.utils import PY3

# baidu-aip for audio recognize
""" 你的 APPID AK SK """
APP_ID = '11031096'
API_KEY = 'Znj7ZUGi7HK93nDEGAXdzAjI'
SECRET_KEY = '64c3e4a4ba912a4e0dde68fafbea127e'

# 19430124 FAN Shuaishuai 's redis
HOST = "redis-13670.c8.us-east-1-4.ec2.cloud.redislabs.com"
PWD = "uOugljWUzWvmfoDuf6CRsonlrfUmYKSD"
PORT = "13670"

client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
redis1 = redis.Redis(host=HOST, password=PWD, port=PORT, decode_responses=True)


def get_module_dir(name):
    '''
    get alice module
    :param name:
    :return:
    '''
    path = getattr(sys.modules[name], '__file__', None)
    if not path:
        raise AttributeError('module %s has not attribute __file__' % name)
    return os.path.dirname(os.path.abspath(path))

示例#9
0
def reg():

    RESPEAKER_RATE = 16000
    RESPEAKER_CHANNELS = 1
    RESPEAKER_WIDTH = 2
    CHUNK = 1024
    RECORD_SECONDS = 2
    #WAVE_OUTPUT_FILENAME = "output.wav"

    p = pyaudio.PyAudio()
    stream = p.open(
        rate=RESPEAKER_RATE,
        format=p.get_format_from_width(RESPEAKER_WIDTH),
        channels=RESPEAKER_CHANNELS,
        input=True,
        start=False,
    )

    APP_ID = '10783244'
    API_KEY = 'GlQae1odOq3Y1w2wCpGBOI27'
    SECRET_KEY = 'aeb8dc5f91cc18990a873edb294e6641'

    aipSpeech = AipSpeech(APP_ID, API_KEY, SECRET_KEY)

    baidu = BaiduVoiceApi(appkey=API_KEY, secretkey=SECRET_KEY)

    def generator_list(list):
        for l in list:
            yield l

    def record():
        stream.start_stream()
        print("* recording")
        frames = []
        for i in range(0, int(RESPEAKER_RATE / CHUNK * RECORD_SECONDS)):
            data = stream.read(CHUNK)
            frames.append(data)
        print("* done recording")
        stream.stop_stream()
        print("start to send to baidu")
        # audio_data should be raw_data
        text = baidu.server_api(generator_list(frames))
        if text:
            try:
                text = json.loads(text)
                for t in text['result']:
                    print(t)
                    return (t)
            except KeyError:
                return ("get nothing")
        else:
            print("get nothing")
            return ("get nothing")

    word_0 = "开"
    word_1 = "快"
    os.system("play dong.wav")
    outputtext = record()
    if word_0 in outputtext:
        os.system("play ./turnon.mp3")
    print outputtext
    stream.close()
    p.terminate()
示例#10
0
from aip.speech import AipSpeech

appId = '10749810'
apiKey='cxIvL8MP2PBVArtcLCYXZNdC'
secret = '6ef14e35f5376de5fa8b3377ccd7c4bb'


# def get_file_content(filePath):
#     with open(filePath, 'rb') as fp:
#         return fp.read()
aipSpeech = AipSpeech(appId,apiKey,secret)
vioceFile = open('vioce/180125-230730.wav','rb')
vioce = vioceFile.read()
result = aipSpeech.asr(vioce,'pcm')
print(result)
示例#11
0
#coding:utf-8
import time
from aip.speech import AipSpeech
import os
import sys
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.path.join(BASE_DIR, '../'))
#print(sys.path)
from common import config

APP_ID = config.get('/baidu_yuyin/appid', '17127791')
API_KEY = config.get('/baidu_yuyin/api_key', 'UY5hD5DgwnPB9DPPVVkjGenN')
SECRET_KEY = config.get('/baidu_yuyin/secret_key',
                        'wxhyyGEpTtajKLDOuTUUBAUopTzqEkSp')

aipSpeech = AipSpeech(APP_ID, API_KEY, SECRET_KEY)

#string = '现在温度是{}摄氏度'.format(27.0)
strings = [
    ' 好的主人,马上为您开块一点', ' 来啦', ' 来咯', ' 我在呢', ' 我在', ' 在呢', ' 好的', ' 欧克', '想我了?'
]
i = 0
print('per:' + str(config.get('/baidu_yuyin/per')))
for _str in strings:
    result = aipSpeech.synthesis(_str, 'zh', 1, {
        'vol': 5,
        'per': config.get('/baidu_yuyin/per', 0),
    })
    # 识别正确返回语音二进制 错误则返回dict 参照下面错误码
    if not isinstance(result, dict):
        fileName = 'staticData/sysvoices/sysvoice' + str(i) + '.mp3'