read-text.vue 958 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <template>
  2. <view class="">
  3. </view>
  4. </template>
  5. <script>
  6. var plugin = requirePlugin("WechatSI")
  7. let manager = plugin.getRecordRecognitionManager()
  8. export default {
  9. data() {
  10. return {
  11. };
  12. },
  13. created() {
  14. this.innerAudioContext = wx.createInnerAudioContext();
  15. this.innerAudioContext.onError(function(res) {
  16. uni.showToast({
  17. title: '语音播放初始化失败',
  18. })
  19. })
  20. },
  21. methods: {
  22. //阅读文字
  23. read(content) {
  24. var that = this;
  25. plugin.textToSpeech({
  26. lang: "zh_CN",
  27. tts: true,
  28. content,
  29. success: function(res) {
  30. that.auidoSrc=res.filename
  31. that.doRead();
  32. },
  33. fail: function(res) {
  34. wx.showToast({
  35. title: '语音转换失败',
  36. })
  37. }
  38. })
  39. },
  40. doRead() {
  41. this.innerAudioContext.src = this.auidoSrc //设置音频地址
  42. this.innerAudioContext.play(); //播放音频
  43. },
  44. }
  45. };
  46. </script>
  47. <style lang="scss" scoped>
  48. </style>