performance - Python 3.6: How to play audio faster -


so, have bit of code print out text in delayed fashion see in old school or indie video games.

everything working, not way want to. want printing , playing of sound faster right slow.

is there way make possible?

here code:

note: lags in pycharm works fine in terminal/cmd.

import sys import time pydub import audiosegment pydub.playback import play    def print_delay(string_in):     sound_1 = "text_beep.wav"     sound_play = audiosegment.from_wav(sound_1)       char in string_in:         sys.stdout.write(char)         sys.stdout.flush()         play(sound_play)          if char != ",":             time.sleep(0.01)         if char == ".":             time.sleep(0.20)         if char == ",":             time.sleep(0.10)      print("\n")  string_hello = "hello world, sample text.\ni want want print out faster without being delayed sound file.\nis there faster way this?"  print_delay(string_hello) 

woohoo! ok figured out.

use module named: "pyglet"

im not 100% sure looks pyglet lets specify sound file short sound. if cases can pass argument "streaming = false" tells play sound , in turn use less cpu power. i'm not sure if making sound file play way want might.

if knows sure please let me know.

here source: https://pythonhosted.org/pyglet/programming_guide/playing_sounds_and_music.html

import sys import time import pyglet    def print_delay(string_in):     sound_1 = pyglet.resource.media("text_beep.wav", streaming=false)       char in string_in:         sound_1.play()         sys.stdout.write(char)         sys.stdout.flush()          if char != ",":             time.sleep(0.05)         if char == ".":             time.sleep(0.70)         if char == ",":             time.sleep(0.50)       print("\n")  string_hello = "hello world, sample text.\ni want want print out faster without being delayed sound file.\nis there faster way this?"  print_delay(string_hello) 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -