import request from "@/config/request.js";
import requesta from "@/config/requesta.js";

export function xuiat(data) {
	return request.post(`xun_fei/tts`, data);
}

export function feiiat(data) {
	return request.post(`xun_fei/iat`, data);
}

export function iatWss(data) {
	return request.post(`xun_fei/iatWss`, data);
}
// http://chat.lihaink.cn/index/tts
//文字转语音
export function ttWss(data) {
	return requesta.post(`index/tts`, data);
}

//图片识别
export function ttocr(data) {
	return request.post(`xun_fei/ocr`, data);
}




// base64 转 二进制流(blob)
export function dataURLtoBlob(dataurl) {
    // console.log(dataurl);
    // let str = "data:audio/wav;base64," + dataurl.slice(2)
    // console.log(str);
    let mime = "audio/wav"
    // var arr = str.split(","),
    // mime = arr[0].match(/:(.*?);/),
    // let bstr = atob(arr[1])
    let bstr = atob(dataurl)
    let n = bstr.length
    let u8arr = new Uint8Array(n);
    while (n--) {
        u8arr[n] = bstr.charCodeAt(n);
    }
	console.log(u8arr)
    // return new Blob([u8arr], {
    //     type: mime,
    // });
}


// -防抖
export function debounce(fn, wait) {
	let delay = wait || 500
	let timer
	return function() {
		let args = arguments;
		if (timer) {
			clearTimeout(timer)
			console.log('拦截')
		}
		let callNow = !timer
		timer = setTimeout(() => {
			console.log('发送')
			timer = null
		}, delay)
		if (callNow) fn.apply(this, args)
	}
}

// -节流
export function throttle(fn, wait) {
	let delay = wait || 500
	let timer = null
	return function() {
		if (timer) {
			console.log('拦截');
			return
		}
		timer = setTimeout(() => {
			console.log('发送');
			fn.apply(this, arguments)
			timer = null
		}, delay)
	}
}