2013-12-14 5 views
0

mp3 파일을 재생 중입니다. Google에 요청한 후 변환됩니다. 내가 파이 게임을 통해 재생할 때 상관없이 내가 여기파이 게임 재생 속도가 너무 빠름 (내가 정의한 주파수에 관계없이)

pygame.mixer.init()에서 설정 한 어떤 주파수의 두 배 속도로 재생되는 코드입니다 :

import tweepy, urllib, os, pygame, pycurl, difflib, time 
pygame.init() 
pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096) 

consumer_key = 'xxxxxxxxx' 
consumer_secret = 'xxxxxxxx' 
access_token = 'xxxxxx' 
access_token_secret = 'xxxxxx' 

auth = tweepy.OAuthHandler(consumer_key, consumer_secret) 
auth.set_access_token(access_token, access_token_secret) 

# function to download a file from a url, used for testing 
def downloadFile(url, fileName): 
    fp = open(fileName, "wb") 
    curl = pycurl.Curl() 
    curl.setopt(pycurl.URL, url) 
    curl.setopt(pycurl.WRITEDATA, fp) 
    curl.perform() 
    curl.close() 
    fp.close() 

# returns the appropriate google speech url for a particular phrase 
def getGoogleSpeechURL(phrase): 
    googleTranslateURL = "http://translate.google.com/translate_tts?tl=en&" 
    parameters = {'q': phrase} 
    data = urllib.urlencode(parameters) 
    googleTranslateURL = "%s%s" % (googleTranslateURL,data) 
    return googleTranslateURL 

def speakSpeechFromText(phrase): 
    googleSpeechURL = getGoogleSpeechURL(phrase.encode('utf-8').strip()) 
    downloadFile(googleSpeechURL,"tts.mp3") 
    pygame.mixer.music.load("tts.mp3") 
    pygame.mixer.music.play(0,0.0) 
    while pygame.mixer.music.get_busy(): 
     pygame.time.Clock().tick(10) 
    #os.system("mplayer tts.mp3 -af extrastereo=0 &") 


def diffindex(string1, string2): 
    for i, (char1, char2) in enumerate(zip(string1, string2)): 
     if char1 != char2: 
      return 1 
    return 2 

A = "a" 
B = "b" 

api = tweepy.API(auth) 

while(true) 
    results = api.search(q="Hackney", count=1, result_type="recent") 
    for result in results: 
     A = result.text 

    if diffindex(A, B) != 2: 
     speakSpeechFromText(A) 
     B = A 
    else: 
     print ("jaha") 
    time.sleep(20) 

죄송 경우 관련성이없는 물건의 탑승객 중에 많이도하지만 사용의 가능성이 있다고 생각했습니다.

+0

당신이 당신의 컴퓨터에있는 MP3 파일과 함수 "speakSpeechFromText"를 시도? 그렇다면 파일이 해당 빈도로 재생 되었습니까? 나는 윈앰프에서 모든 오디오 파일의 주파수가 어떻게 변하는지를 보았는데, 일부는 48000 Hz에서 "Joint Stereo"라는 것을 사용했다. 그리고 진드기가 10에서 15 또는 20으로 변하는 것은 어떨까요? –

답변

0

pygame.init()도 믹서를 초기화하기 때문에 pygame.init() 전에 mixer.init()으로 전화해야합니다.

pygame.init() 첫 번째 전화 mixer.quit() 이후에 mixer.init()으로 전화해야하는 경우.

모두입니다. in the docs :)입니다.

0

겠어요 :

pygame.mixer.pre_init(16000, -16, 2, 2048) # setup mixer to avoid sound lag 
pygame.mixer.init() 
pygame.mixer.music.load("mymp3file.mp3") 
pygame.mixer.music.play() 
# I adjusted the 16000 - it was 44100, tryied 48000, 22000, 110000 and themn 16000