本文整理汇总了Python中pygame.mixer.init函数的典型用法代码示例。如果您正苦于以下问题:Python init函数的具体用法?Python init怎么用?Python init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pronounce
def pronounce(self, what):
ie = 'UTF-8'
if what == 'src':
tl = self.language_code[self.src_lang.get().encode('utf8')]
whole_text = self.input_box.get('1.0', END).strip()
elif what == 'target':
tl = self.language_code[self.target_lang.get().encode('utf8')]
whole_text = self.output_box.get('1.0', END).strip()
# Split the original text into small chunks and make separate requests to Google.
# All the returned mp3 files will be concatenated and then played.
total_length = len(whole_text)
max_chunk_length = 100
total = total_length / max_chunk_length + 1 if total_length % max_chunk_length else total_length / max_chunk_length # total number of chunk
temp_mp3 = tempfile.TemporaryFile(mode='r+')
for i in xrange(total):
if i == total - 1:
q = whole_text.encode('utf8')
else:
q = whole_text[:max_chunk_length].encode('utf8')
whole_text = whole_text[max_chunk_length:]
data = {'ie': ie, 'tl': tl, 'q': q, 'total': total, 'idx': str(i)}
data = urllib.urlencode(data)
url = 'https://translate.google.cn/translate_tts'
header = {'User-Agent': 'Mozilla/5.0'}
req = urllib2.Request(url, data, header)
temp_mp3.write(urllib2.urlopen(req).read())
temp_mp3.seek(0)
mixer.init()
mixer.music.load(temp_mp3)
mixer.music.play()
示例2: todo_test_pre_init__keyword_args
def todo_test_pre_init__keyword_args(self):
# Fails on Mac; probably older SDL_mixer
## Probably don't need to be so exhaustive. Besides being slow the repeated
## init/quit calls may be causing problems on the Mac.
## configs = ( {'frequency' : f, 'size' : s, 'channels': c }
## for f in FREQUENCIES
## for s in SIZES
## for c in CHANNELS )
configs = [{'frequency' : 44100, 'size' : 16, 'channels' : 1}]
for kw_conf in configs:
mixer.pre_init(**kw_conf)
mixer.init()
mixer_conf = mixer.get_init()
self.assertEquals(
# Not all "sizes" are supported on all systems.
(mixer_conf[0], abs(mixer_conf[1]), mixer_conf[2]),
(kw_conf['frequency'],
abs(kw_conf['size']),
kw_conf['channels'])
)
mixer.quit()
示例3: initPygame
def initPygame(rate=22050, bits=16, stereo=True, buffer=1024):
"""If you need a specific format for sounds you need to run this init
function. Run this *before creating your visual.Window*.
The format cannot be changed once initialised or once a Window has been created.
If a Sound object is created before this function is run it will be
executed with default format (signed 16bit stereo at 22KHz).
For more details see pygame help page for the mixer.
"""
global Sound, audioDriver
Sound = SoundPygame
audioDriver='n/a'
if stereo==True: stereoChans=2
else: stereoChans=0
if bits==16: bits=-16 #for pygame bits are signed for 16bit, signified by the minus
mixer.init(rate, bits, stereoChans, buffer) #defaults: 22050Hz, 16bit, stereo,
sndarray.use_arraytype("numpy")
setRate, setBits, setStereo = mixer.get_init()
if setRate!=rate:
logging.warn('Requested sound sample rate was not poossible')
if setBits!=bits:
logging.warn('Requested sound depth (bits) was not possible')
if setStereo!=2 and stereo==True:
logging.warn('Requested stereo setting was not possible')
示例4: play
def play(self, song_thread):
music_file = "output" + str(self.id) + ".mid"
clock = time.Clock()
freq = 44100 # audio CD quality
bitsize = -16 # unsigned 16 bit
channels = 2 # 1 is mono, 2 is stereo
buffer = 1024 # number of samples
mixer.init(freq, bitsize, channels, buffer)
# optional volume 0 to 1.0
mixer.music.set_volume(0.8)
try:
try:
mixer.music.load(music_file)
print "Music file %s loaded!" % music_file
except error:
print "File %s not found! (%s)" % (music_file, get_error())
return
mixer.music.play()
while mixer.music.get_busy():
# check if playback has finished
clock.tick(30)
except KeyboardInterrupt:
#if user hits Ctrl/C then exit
#(works only in console mode)
#modify to work on GUI
mixer.music.fadeout(1000)
mixer.music.stop()
print 'lolno'
raise SystemExit
song_thread.join()
示例5: test_get_raw_more
def test_get_raw_more(self):
""" test the array interface a bit better.
"""
import platform
IS_PYPY = 'PyPy' == platform.python_implementation()
if IS_PYPY:
return
from ctypes import pythonapi, c_void_p, py_object
try:
Bytes_FromString = pythonapi.PyBytes_FromString
except:
Bytes_FromString = pythonapi.PyString_FromString
Bytes_FromString.restype = c_void_p
Bytes_FromString.argtypes = [py_object]
mixer.init()
try:
samples = as_bytes('abcdefgh') # keep byte size a multiple of 4
snd = mixer.Sound(buffer=samples)
raw = snd.get_raw()
self.assertTrue(isinstance(raw, bytes_))
self.assertNotEqual(snd._samples_address, Bytes_FromString(samples))
self.assertEqual(raw, samples)
finally:
mixer.quit()
示例6: send
def send(self, info):
url_tuling = self.apiurl + 'key=' + self.key + '&' + 'info=' + str(info)
tuling = urllib2.urlopen(url_tuling)
re = tuling.read()
re_dict = json.loads(re)
text = re_dict['text']
text = text.encode('utf-8')
#print '回答是: ', text
#文本轉語音
url = 'http://apis.baidu.com/apistore/baidutts/tts?text='+str(text)+'&ctp=1&per=0'
f1 = open('test.mp3', 'w')
req = urllib2.Request(url)
req.add_header("apikey", " f6805eda3bd2a46de02ab4afa7a506a0")
resp = urllib2.urlopen(req)
content = resp.read()
result = json.loads(content, 'utf-8')
answer = result['retData']
decoded_content = base64.b64decode(answer)
f1.write(decoded_content)
f1.close()
print '- ', text
mixer.init()
mixer.music.load('test.mp3')
mixer.music.play()
time.sleep(2)
self.get()
示例7: Konusma
def Konusma(self):
try:
mixer.init()
mixer.music.load('Dosyalar/x.wav')
mixer.music.play()
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
konusma = r.recognize_google(audio, language="tr")
print(konusma)
return konusma
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
except:
print('Kelime Algılanamadı')
mixer.init()
mixer.music.load('Dosyalar/x.wav')
mixer.music.play()
self.dugme.bind(on_press=self.Tikla)
示例8: GET
def GET(self, cmd):
mixer.init(44100)
mixer.music.set_volume(1.0)
p = paused
#I feel it would have been too robust or unsuitable
#to use a Command pattern in this scenario
if(cmd == "play"):
songloc = list(mydb.getPlaylist())
if(songloc):
mixer.music.load(songloc[0].loc)
mixer.music.play(0)
if(cmd == "pause"):
if(p):
mixer.music.unpause()
p = False
else:
mixer.music.pause()
p = True
if(cmd == "next"):
delfirst = mydb.delFirstPl()
nextsong = list(mydb.getPlaylist())
if(nextsong):
mixer.music.load(nextsong[0].loc)
mixer.music.play(0)
if(cmd == "stop"):
mixer.music.stop()
return cmd
示例9: send
def send(self, info):
url_tuling = self.apiurl + 'key=' + self.key + '&' + 'info=' + info
tuling = urllib2.urlopen(url_tuling)
re = tuling.read()
re_dict = json.loads(re)
text = re_dict['text']
text = text.encode('utf-8')
#text = '你好啊,希望你今天过的快乐'
#print(chardet.detect(text))
url = 'http://apis.baidu.com/apistore/baidutts/tts?text='+text+'&ctp=1&per=0'
f1 = open('test.mp3', 'w')
req = urllib2.Request(url)
req.add_header("apikey", " f6805eda3bd2a46de02ab4afa7a506a0")
resp = urllib2.urlopen(req)
content = resp.read()
result = json.loads(content, 'utf-8')
decoded_content = base64.b64decode(result['retData'])
f1.write(decoded_content)
f1.close()
print '- ', text
mixer.init()
mixer.music.load('test.mp3')
mixer.music.play()
self.get()
示例10: __init__
def __init__(self):
mixer.init()
self.track = interruption
mixer.music.load(self.track)
self.volume = 0
mixer.music.play(-1)
self.playing = True
示例11: __init__
def __init__(self, settings):
self.speed = int(settings['-r']) if '-r' in settings else 20
self.scale = float(settings['-s']) if '-s' in settings else 1.0
self.screen = curses.initscr()
self.START_INTENSITY = int(settings['-i']) if '-i' in settings else self.MAX_INTENSITY
self.START_OFFSET = int(settings['-w']) if '-w' in settings else 0
self.START_HEIGHT = int(settings['-h']) if '-h' in settings else 0
self.screen.clear()
self.screen.nodelay(1)
curses.curs_set(0)
curses.start_color()
curses.use_default_colors()
for i in range(0, curses.COLORS):
curses.init_pair(i, i, -1)
def color(r, g, b):
return (16+r//48*36+g//48*6+b//48)
self.heat = [color(16 * i,0,0) for i in range(0,16)] + [color(255,16 * i,0) for i in range(0,16)]
self.particles = [ord(i) for i in (' ', '.', '*', '#', '@')]
assert(len(self.particles) == self.NUM_PARTICLES)
self.resize()
self.volume = 1.0
if pygame_available:
mixer.init()
music.load('fire.wav')
music.play(-1)
elif pyaudio_available:
self.loop = True
self.lock = threading.Lock()
t = threading.Thread(target=self.play_fire)
t.start()
示例12: setup
def setup():
random.seed()
mixer.init()
#screen = pygame.display.set_mode ((640, 480), 0, 32)
samples = get_samples("./samples")
init_playfield(samples)
tick()
print_playfield()
pygame.init ()
#screen.fill ((100, 100, 100))
#pygame.display.flip ()
#pygame.key.set_repeat (500, 30)
#mixer.init(11025)
#mixer.init(44100)
#sample = samples[random.randint(0,len(samples)-1)]
#print("playing sample:",sample)
#sound = mixer.Sound(sample)
#channel = sound.play()
while True:
play_sounds()
#for i in range(2):
mutate_playfield()
tick()
print_playfield()
#time.wait(int((1000*60)/80)) # 128bpm
time.wait(50)
#while channel.get_busy(): #still playing
# print(" ...still going...")
# time.wait(1000)
#print("...Finished")
pygame.quit()
示例13: play_songfile
def play_songfile(self):
print('playing song...')
mixer.init()
mixer.music.load(self.song_file)
mixer.music.play(-1)
while mixer.music.get_busy() == True:
continue
示例14: main
def main(argv):
mixer.init(44100)
mixer.set_num_channels(20)
load_res("./res")
app = App()
app.MainLoop()
示例15: updateDisplay
def updateDisplay(self, msg):
"""
recibe datos desde el hilo y actualiza el control
"""
self.mpc.Pause()
mixer.init()
mixer.music.load("campana.mp3")
mixer.music.play()
t = msg.data
if t.strip() == 'adios':
self.cerrar_form(self)
if '^' in t:
lcPaciente, lcEspecialidad = t.split('^')
lcPacienteDecode = lcPaciente.decode('latin-1')
#Llama al paciente con Voz
#comando_de_voz = "espeak -s140 -v 'es-la'+f2 '%s'" % (lcPacienteDecode)
comando_de_voz = "espeapeak -p 80 -s 120 -v mb-vz1 '%s'" % (lcPacienteDecode)
os.system(comando_de_voz)
ultimo = lcPacienteDecode + '-' + lcEspecialidad
if len(ultimo) >0:
self.list_ctrl_llamados.InsertStringItem(self.pos, ultimo)
self.pos = 0
self.text_ctrl_turno.Value = lcPacienteDecode.strip()
self.text_ctrl_especialidad.Value = lcEspecialidad.strip()
time.sleep(1)
self.mpc.Pause()
self.mpc.SetProperty('volume', 0)
'''