简体   繁体   English

如何在visual studio代码中使用gTTS(谷歌文本到语音)?

[英]How to use gTTS (google text to speech) in visual studio code?

I want to use the google text to speech(gTTS) in my visual studio code project. 我想在我的visual studio代码项目中使用谷歌文本到语音(gTTS)。 I need help with: a) downloading it b)using it in VS Code c) running it in VS Code 我需要帮助:a)下载它b)在VS Code中使用它c)在VS Code中运行它

I've been really confused on trying to use this module and other modules in VS Code. 我一直很困惑,试图在VS Code中使用这个模块和其他模块。

Thanks for helping in advance, if anything is unclear leave a comment and i'll update the question! 感谢提前帮助,如果有什么不清楚留下评论,我会更新问题!

If I understand your question correctly, then you just need to install the gTTS module using pip install gTTS from the terminal (to this you need to have python set to path). 如果我正确理解你的问题,那么你只需要使用pip install gTTS从终端安装gTTS模块(为此你需要将python设置为路径)。

Demonstration of install of gTTS in VS code 演示在VS代码中安装gTTS

To open the terminal in VS code you can use the keyboard shortcut Ctrl + Shift + P to bring up the command pallet, where in you can type terminal and then you will see a option to open the terminal in VS code. 要在VS代码中打开终端,您可以使用键盘快捷键Ctrl + Shift + P出命令托盘,您可以在其中输入terminal ,然后您将看到在VS代码中打开终端的选项。

Opening the terminal in VS code 在VS代码中打开终端

Then you will be able to use the module in your python files like this: 然后你就可以在你的python文件中使用这个模块,如下所示:

>>> from gtts import gTTS
>>> tts = gTTS('hello')
>>> tts.save('hello.mp3')

This piece will take the string and save it as a mp3 file of the gTTS voice from the text in line 2. 这篇文章将把字符串保存为第2行文本中gTTS语音的mp3文件。

Demonstration of the code-example in VS code 演示VS代码中的代码示例

For more information go to the official site for gTTS: https://pypi.org/project/gTTS/ 有关更多信息,请访问官方网站获取gTTS: https ://pypi.org/project/gTTS/

For using python modules in VS code or any other editor is just the matter of installing them using the guidance on the module's website (sometimes one needs to restart the editor before one can use the module). 在VS代码中使用python模块或任何其他编辑器只需使用模块网站上的指南安装它们(有时需要重新启动编辑器才能使用该模块)。 Then to use the module one just needs to import it in the beginning og the file, that the module needs to be used. 然后使用模块只需要在文件的开头导入它,模块需要使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM