| | |
| | | * @Author: Morpheus |
| | | * @Date: 2021-03-17 15:21:33 |
| | | * @Last Modified by: Morpheus |
| | | * @Last Modified time: 2021-03-19 11:53:17 |
| | | * @Last Modified time: 2021-03-19 15:21:40 |
| | | */ |
| | | <template> |
| | | <basic-container> |
| | |
| | | |
| | | this.recorder = new Recorder({ |
| | | sampleBits: 16, // 采样位数,支持 8 或 16,默认是16 |
| | | sampleRate: 16000, // 采样率,支持 11025、16000、22050、24000、44100、48000,根据浏览器默认值,我的chrome是48000 |
| | | sampleRate: 8000, // 采样率,支持 11025、16000、22050、24000、44100、48000,根据浏览器默认值,我的chrome是48000 |
| | | numChannels: 1, // 声道,支持 1 或 2, 默认是1 |
| | | // compiling: false,(0.x版本中生效,1.x增加中) // 是否边录边转换,默认是false |
| | | }); |
| | |
| | | }); |
| | | |
| | | setInterval(() => { |
| | | // 一键呼叫相关函数 |
| | | if (this.isActive == true) { |
| | | this.isActive = false; |
| | | newCallAxios |
| | | .post( |
| | | `/api_control`, |
| | | {}, |
| | | { |
| | | params: { |
| | | param: { PktType: "GetAccessToken" }, |
| | | }, |
| | | } |
| | | ) |
| | | .then((result) => { |
| | | var formData = new FormData(); |
| | | var blob = this.recorder.getPCMBlob(); //获取pcm格式音频数据 |
| | | //此处获取到blob对象后需要设置fileName满足当前项目上传需求,其它项目可直接传把blob作为file塞入formData |
| | | var newbolb = new Blob([blob], { type: "audio/pcm" }); |
| | | var fileOfBlob = new File( |
| | | [newbolb], |
| | | new Date().getTime() + ".pcm" |
| | | ); |
| | | formData.append("file", fileOfBlob); |
| | | |
| | | // var dom = document.getElementById("real_audio"); |
| | | // dom.setAttribute("src", URL.createObjectURL(blob)); |
| | | |
| | | // this.recorder.play(); |
| | | |
| | | newCallAxios |
| | | .post(`/api_control`, blob, { |
| | | Recorder.getPermission().then(() => { |
| | | this.recorder.start().then(() => { |
| | | // 开始录音 |
| | | newCallAxios |
| | | .post( |
| | | `/api_control`, |
| | | {}, |
| | | { |
| | | params: { |
| | | param: { |
| | | PktType: "Talk", |
| | | accessToken: result.data.data.accessToken, |
| | | // deviceCode: form.channelNumber, |
| | | deviceCode: "001231663A45", |
| | | }, |
| | | param: { PktType: "GetAccessToken" }, |
| | | }, |
| | | }) |
| | | .then((result) => {}); |
| | | }); |
| | | } else { |
| | | this.isActive = true; |
| | | Recorder.getPermission().then(() => { |
| | | this.recorder.start().then(() => { |
| | | // 开始录音 |
| | | }); |
| | | } |
| | | ) |
| | | .then((result) => { |
| | | var formData = new FormData(); |
| | | var blob = this.recorder.getPCMBlob(); //获取pcm格式音频数据 |
| | | //此处获取到blob对象后需要设置fileName满足当前项目上传需求,其它项目可直接传把blob作为file塞入formData |
| | | var newbolb = new Blob([blob], { type: "audio/pcm" }); |
| | | var fileOfBlob = new File( |
| | | [newbolb], |
| | | new Date().getTime() + ".pcm" |
| | | ); |
| | | formData.append("file", fileOfBlob); |
| | | |
| | | // var dom = document.getElementById("real_audio"); |
| | | // dom.setAttribute("src", URL.createObjectURL(blob)); |
| | | |
| | | // this.recorder.play(); |
| | | |
| | | newCallAxios |
| | | .post(`/api_control`, blob, { |
| | | params: { |
| | | param: { |
| | | PktType: "Talk", |
| | | accessToken: result.data.data.accessToken, |
| | | // deviceCode: form.channelNumber, |
| | | deviceCode: "001231663A45", |
| | | }, |
| | | }, |
| | | }) |
| | | .then((result) => {}); |
| | | }); |
| | | }); |
| | | } |
| | | }, 5000); |
| | | }); |
| | | |
| | | // 一键呼叫相关函数 |
| | | }, 200000); |
| | | }, |
| | | peopleOrPhone(e) { |
| | | this.peopleList.forEach((item) => { |