嗨我正在使用語音合成在Mac上進行實驗,並且我總是將while循環放在我的程序中,以便我可以使用它們直到我決定停止,並且使用此代碼重複「您希望我說什麼?同時它說了我所說的任何話。如何讓Python等到前一個任務完成?
from Cocoa import NSSpeechSynthesizer
while 1==1
sp = NSSpeechSynthesizer.alloc().initWithVoice_(None)
sp.startSpeakingString_("What would you like me to say?")
say_1 = raw_input("What would you like me to say?")
sp.startSpeakingString_(say_1)
有人可以告訴我如何告訴python等待,直到它說完我告訴它什麼?
那麼這取決於什麼'sp.startSpeaking'呢? NSSpeechSynthesizer的責任似乎比Python本身更重要。那個類沒有類似'sp.waitUntilIsSaid'的方法嗎? –
我無法測試它,所以我不會讓它成爲答案,但請查看API中的實例方法'isSpeaking'(https://developer.apple.com/library/mac/documentation/Cocoa/參考/ ApplicationKit /類/ NSSpeechSynthesizer_Class/Reference/Reference.html#jumpTo_12)似乎你可以循環,直到_it不speaking_。這樣你可以等待它完成。 –
@PauloBu這篇文檔對Python的使用非常不清楚。你對我如何使用它有任何想法嗎? – user3151828