Beispiel #1
0
def audio2text(filepath):
    res = SPEECH.asr(get_file_content(filepath), 'pcm', 16000,
                     {'<dev_pid></dev_pid>': 1536})
    print('123', filepath, res)
    print(res.get('result')[0])

    return res.get('result')[0]
Beispiel #2
0
def audio2text(filepath):
    # 识别本地文件
    res = SPEECH.asr(get_file_content(filepath), 'pcm', 16000, {
        'dev_pid': 1536,
    })

    print(res.get("result")[0])

    return res.get("result")[0]
Beispiel #3
0
def text2audio(text):
    filename = f'{uuid4()}.mp3'
    result = SPEECH.synthesis(text, 'zh', 1, VOICE)
    file_path = os.path.join(CHATS_PATH, filename)

    if not isinstance(result, dict):
        with open(file_path, 'wb') as f:
            f.write(result)

    return filename
Beispiel #4
0
def text2audio(text):
    filename = f"{uuid4()}.mp3"
    result = SPEECH.synthesis(text, 'zh', 1, VOICE)
    file_path = os.path.join(CHATS_PATH, filename)

    # 识别正确返回语音二进制 错误则返回dict 参照下面错误码
    if not isinstance(result, dict):
        with open(file_path, 'wb') as f:
            f.write(result)

    return filename
Beispiel #5
0
def text2audio(text):
    filename = f"{uuid4()}.mp3"
    file_path = os.path.join(CHAT_PATH, filename)
    res = SPEECH.synthesis(text, options={
        "vol": 8,
        "pit": 8,
        "spd": 5,
        "per": 4
    })

    with open(file_path, "wb") as f:
        f.write(res)

    return filename
Beispiel #6
0
def audio2text(filename):
    res = SPEECH.asr(speech=get_file_content(filename), options={
        "dev_pid": 1536,
    })

    return res.get("result")[0]