首页 > 解决方案 > 世博会文字转语音无法在 iPhone 7 上运行

问题描述

我有以下使用 Expo SDK 的反应本机代码。我正在我的 iphone 7 上对此进行测试。文本到语音部分根本不起作用。如何解决这个问题?github上有一个类似的问题是开放的。

Github问题

import React from 'react';
import { StyleSheet, Text, View,Button } from 'react-native';
import * as Speech from 'expo-speech';

export default class App extends React.Component {

  constructor(props)
  {
    super(props)
    this.state={word:""}
  }

  async readFile(){
    fetch("https://random-word-api.herokuapp.com/word?number=1")
    .then((response)=>response.json())
    .then((response)=>{this.setState({word:response[0]})})

  }

  componentDidMount(){
    this.readFile()
  }

  speak(){
    console.log("WORD IS "+this.state.word)
    Speech.speak(this.state.word)
  }

  render(){
  return (
    <View style={styles.container}>
      <Text>{this.state.word}</Text>
      <Button title="ANOTHER WORD" onPress={()=>this.readFile()}></Button>
      <Button title="SPEAK" onPress={()=>this.speak()}></Button>
    </View>
  );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

标签: javascriptreact-nativeexpotext-to-speech

解决方案


推荐阅读