Python gtts vlc播放速度太快,无法听到前几个单词 [英] Python gtts vlc plays too quickly to hear the first couple words

查看:60
本文介绍了Python gtts vlc播放速度太快,无法听到前几个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在python中,我使用gTTS和VLC-python模块创建了一个文本到语音程序,该程序非常简单.

In python, using the module gTTS and VLC-python, I've created a Text to speech program, which is quite simple to do.

但是困扰我的是,当我播放由gTTS创建的mp3文件时,它会跳过第一个或两个单词.

But the thing which is bugging me is when I get to playing the mp3 file created by gTTS it skips the first word or two.

因此,如果我输入字符串今天的天气将是阴天".它会说今天将是阴天"

So if I have the string "The weather today will be cloudy". It'll speak out "today will be cloudy"

即使我调整了字符串,它似乎也会漏掉第一个或两个单词,有时甚至会从中间单词开始.

Even if I adjust the string, it seems to miss out the first word or two, sometimes it starts mid word.

当我在代码之外播放音频文件时,它会正常播放,有时会在第一个单词上出现断断续续的声音,但是如果我倒带并等待一秒钟,它会完美播放.

When I play the audio file outside of the code, it plays normally, sometimes it stutters on the first word but if I rewind and have it wait a second, it plays perfectly.

有没有一种方法可以在播放之前加载音频片段或对其进行缓冲,以使其顺利启动?

Is there a way to load the audio clip or buffer it before playing so it starts smoothly?

推荐答案

在您的代码中,您将得到一些类似的东西:

In your code you are going to have something along the lines of:

self.Media = self.Instance.media_new_path('my.mp3')
self.player.set_media(self.Media)
self.player.set_xwindow(self.panel1.GetHandle())

定义要播放的内容.

然后您将得到类似的内容:

Then you will have something like:

if self.player.play() == -1:
    print("Error playing file")
else:
    pass

告诉vlc开始播放文件的位置.

where you tell vlc to start playing the file.

在播放命令之前输入 time.sleep(3)或通过单独的按钮或其他按钮激活播放功能.
这等效于:
vlc --no-playlist-autostart vp.mp3

vlc --start-paused vp.mp3 命令行选项.
即加载文件,但直到我告诉你为止才开始播放.

put a time.sleep(3) before that play command or actuate the play function from a separate button or something.
This is the equivalent of the:
vlc --no-playlist-autostart vp.mp3
or
vlc --start-paused vp.mp3 command line options.
i.e. load the file but don't start playing it, until I tell you.

这篇关于Python gtts vlc播放速度太快,无法听到前几个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆