我的问题从这里开始:
gTTS 运行良好,从文本文件中获取文本,但首先创建 mp3 文件,然后如果我想听,我必须调用这个 mp3,所以这很好,但如果我可以避免任何音频文件会更好,只是从文本文件。也许不知何故我可以使用谷歌语音从文本文件中读取..?无论如何,现在的主要问题是其他
如果我只能使用 gTTS 在 Windows 10-64 位 Python 3.5 上播放 mp3 的最佳方式是什么
好的操作系统:
import os
os.startfile("D:\my path/rec1.mp3")
很好,但我不想使用默认播放器,需要类似 simpleaudio 的 mp3 ...
使用 pygame 我有安装问题,不确定,以这种方式使用它有多好:
from pygame import mixer
mixer.init()
mixer.music.load('D:/my path/rec1.mp3')
mixer.music.play()
vlc 只是如何安装呢?easy_install vlc
我得到了错误:和could not find suitable distribution for requirement.parse ('vlc')
错误pip install vlc
:could not find a version that satisfies the requirement vlc (from versions: ) no matching distribution found for vlc
import vlc
p = vlc.MediaPlayer("file:/my path/rec1.mp3")
p.play()
p.stop()
使用 pyglet:
import pyglet
music=pyglet.media.load('D:/my path/rec1.mp3')
music.play()
pyglet.app.run()
我收到了这个错误:
'AVbin is required to decode compressed media')
pyglet.media.riff.WAVEFormatException: AVbin is required to decode compressed media
subprocess 也使用默认播放器:
import subprocess
sound_program = "path to player"
sound_file = "D:/my path/rec1.mp3"
subprocess.call([sound_program, sound_file])
用mp3play,不知道怎么用:
import mp3play
filename = (r'D:\my path/rec1.mp3')
clip = mp3play.load(filename)
clip.play()
我试过这样:
filename = ('D:\my path/rec1.mp3')
这边走:
filename = r'D:\my path/rec1.mp3'
在所有情况下,我都收到错误:
Traceback (most recent call last):
File "D:/dt/PyCharm_project/0_ASK.py", line 18, in <module>
import mp3play
File "C:\Users\User\AppData\Roaming\Python\Python35\site-packages\mp3play\__init__.py", line 4, in <module>
from .windows import AudioClip as _PlatformSpecificAudioClip
File "C:\Users\User\AppData\Roaming\Python\Python35\site-packages\mp3play\windows.py", line 27
print 'Error %s for "%s": %s' % (str(err), txt, buf)
^
SyntaxError: invalid syntax
好的,pydub:
from pydub import AudioSegment
from gtts import gTTS
import simpleaudio as sa
blabla = ('my voice')
tts = gTTS(text=blabla, lang='en')
tts.save("D:/my path/rec.mp3")
rec = AudioSegment.from_mp3("D:\my path\rec.mp3")
rec.export("rec.wav", format="wav")
#rec = AudioSegment.ffmpeg ("D:\my path\rec.mp3")
#rec.export("rec.wav", format="wav")
#rec = AudioSegment.converter ("D:\my path\rec.mp3")
#rec.export("rec.wav", format="wav")
wave_obj = sa.WaveObject.from_wave_file('D:/my path/rec.wav'')
play_obj = wave_obj.play()
play_obj.wait_done()
序列中的错误首先与AudioSegment.from_mp3
:
RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work
warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)
Traceback (most recent call last):
File " D:/dt/PyCharm_project/0_ASK.py", line 9, in <module>
rec = AudioSegment.from_mp3("D:\my path\rec.mp3")
File "C:\Users\User\AppData\Roaming\Python\Python35\site-packages\pydub\audio_segment.py", line 438, in from_mp3
return cls.from_file(file, 'mp3')
File "C:\Users\User\AppData\Roaming\Python\Python35\site-packages\pydub\audio_segment.py", line 366, in from_file
file = _fd_or_path_or_tempfile(file, 'rb', tempfile=False)
File "C:\Users\User\AppData\Roaming\Python\Python35\site-packages\pydub\utils.py", line 59, in _fd_or_path_or_tempfile
fd = open(fd, mode=mode)
OSError: [Errno 22] Invalid argument: 'D:\my path\rec.mp3'
与AudioSegment.ffmpeg
:
warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)
Traceback (most recent call last):
File "D:/dt/PyCharm_project/0_ASK.py ", line 12, in <module>
rec = AudioSegment.ffmpeg ("D:\my path\rec.mp3")
TypeError: 'str' object is not callable
与AudioSegment.converter
:
RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work
warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)
Traceback (most recent call last):
File "D:/dt/PyCharm_project/0_ASK.py", line 15, in <module>
rec = AudioSegment.converter ("D:\my path\rec.mp3")
TypeError: 'str' object is not callable
不确定也许是网络浏览器,但如何安装它?
import webbrowser
webbrowser.open("D:/my path/rec1.mp3")