Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from gtts import gTTS | |
| from textblob import TextBlob | |
| from io import BytesIO | |
| # 拼写纠错(纯 Python) | |
| def grammar_check(text): | |
| blob = TextBlob(text) | |
| corrected_text = str(blob.correct()) | |
| return corrected_text | |
| # 文本转语音 | |
| def text_to_speech(text): | |
| tts = gTTS(text=text, lang='en') | |
| audio_bytes = BytesIO() | |
| tts.write_to_fp(audio_bytes) | |
| audio_bytes.seek(0) | |
| return audio_bytes | |
| # Gradio 接口函数 | |
| def process_text(text): | |
| corrected = grammar_check(text) | |
| audio = text_to_speech(corrected) | |
| return corrected, audio | |
| # Gradio 界面 | |
| iface = gr.Interface( | |
| fn=process_text, | |
| inputs=gr.Textbox(lines=5, placeholder="输入英文文本..."), | |
| outputs=[gr.Textbox(label="Corrected Text"), gr.Audio(label="Speech")], | |
| title="English Grammar Correction + TTS", | |
| description="输入英文文本,自动纠正拼写并生成语音。" | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |