更新记录
1.1.6(2024-08-30)
优化
1.1.5(2024-08-16)
修复打包报错
1.1.4(2024-08-16)
文件不同步
查看更多平台兼容性
uni-app x
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 | 
|---|---|---|---|---|---|
| - | - | 5.0 | × | - | × | 
xx-audioRecord
开发文档
UTS 语法 UTS API插件 UTS 组件插件 Hello UTS
录制音频使用方法
    import { startAudioRecord, stopAudioRecord } from "@/uni_modules/xx-audioRecord";
    // 开始录制
    startAudioRecord({
        path: `${plus.io.convertLocalFileSystemURL("_doc")}/audioRecord`, // 文件保存目录 可选
        sampleRateInHz: 8000,  // 默认44100
        channelConfig: 1, // 默认2 可选值 1
        audioFormat: 16 // 默认16 可选值 8
    }, (e) => {
        // 开始录制
        console.log(e);
    })
    // 停止录制
    stopAudioRecord((result) => {
        console.log(result);
        result.wavFilePath; // wav文件路径
        result.pcmFilePath; // pcm文件路径
    });文字转语音使用方法
使用TextToSpeech文字转语音无第三方SDK,支持安卓
    import { `useTextToSpeech` } from "@/uni_modules/xx-audioRecord";
    const TextToSpeech = ref(null);
    const classTextToSpeech = () => {
        // 初始化
        TextToSpeech.value = new useTextToSpeech({
            pitch: 1; // 音调
            speechRate: 1; // 语速
            languageTag: "en"; // 语言
            success: (res) => {
                console.log("classTextToSpeech.success.callback", res);
            },
            fail: (res) => {
                console.log("classTextToSpeech.fail.callback", res);
            },
            complete: (res) => {
                console.log("classTextToSpeech.complete.callback", res);
            }
        });
    }
    const speak = () => {
        // 文字转语音
        TextToSpeech.value.speak({
            text: "1, 2, 3, 4, 5, 6, 7, 8, 9, 10",
            onStart: (e) => {
                // 开始朗读
                console.log("onStart", e);
            },
            onDone: (e) => {
                // 完成朗读
                console.log("onDone", e);
            },
            onError: (e) => {
                console.log("onError", e);
            }
        });
    }
    const synthesizeToFile = () => {
        // 文字转语音文件
        TextToSpeech.value.synthesizeToFile({
            text: "6, 7, 8, 9, 10", 
            fileName: "01.pcm", // 可生成不同格式
            onStart: (e) => {
                // 开始
                console.log("onStart", e);
            },
            onDone: (result) => {
                // 生成完成
                console.log("onDone", result);
            },
            onError: (e) => {
                console.log("onError", e);
            }
        })
    }
    const getAvailableLanguages = () => {
        // 获取支持的语言列表
        TextToSpeech.value.getAvailableLanguages();
    }
    const stopSpeak = () => {
        // 停止朗读
        TextToSpeech.value.stop();
    }
    const destroy = () => {
        // 销毁
        TextToSpeech.value.destroy();
    }
    const setPitch = () => {
        // 设置音调,值越大声音越尖(女生),值越小则变成男声,1.0是常规
        TextToSpeech.value.setPitch(0.5);
    }
    const setSpeechRate = () => {
        // 设定语速,默认1.0正常语速
        TextToSpeech.value.setSpeechRate(1.5);
    }

 
                                                                     
                                                                                                                                                 收藏人数:
                                                                        收藏人数:
                                     购买源码授权版(
                                                            购买源码授权版( 试用
                                                                                                                试用
                                                     赞赏(0)
                                        赞赏(0)
                                     下载 53
 下载 53
                 赞赏 0
 赞赏 0
                 
             
                     下载 10661747
                    下载 10661747 
                 赞赏 1797
                        赞赏 1797 
                     
             
                     
             
                     
             
                     
             
                     
             
                     
             
                     
             
                     
             
                     
             
                     
             
                     
             
                     
             
                     
             
                     
             
                     
                         赞赏
                                赞赏
                             
             京公网安备:11010802035340号
京公网安备:11010802035340号