Seite 1 von 1
SDK 5.1 in Python
Verfasst: Freitag 13. April 2007, 12:14
von Markus12
Hi,
ich hab da ein kleines Problem. Ich habe mir ein Programmierbuch gekauft:
"Objektorientierte Programmierung mit python"
Und da habe ich ein Thema gefunden, in dem es um Sprachsynthese geht.
Also, dass der Comuter sprechen kann.
Und unter der Vorraussetzung steht folgendes:
- der Speech SDK 5.1 von Microsoft muss installiert sein.Er kann kostenlos aus dem Internet heruntergeladen werden (
http://microsoft.com/speech/)
- Das Erweiterungspaket "win32all" einschließlich der Entwicklungsumgebung Pythonwin muss installiert sein. Dieses befindet sich auf der CD oder kann auf der Python-Site bezogen werden (
http://www.python.org)
- In der Entwicklungsumgebung "Pythonwin" muss einmal im Menü "Tools" die Funktion "COM MAKEPY UTILITY" angeklickt werden und dann "MICROSOFT SPEECH OBJECT LIBRARY 5.1" selektiert werden.
Man brauch erstmal verdammt lange, um das dann zu finden und auf der Seite stehen verschiedene zur Auswahl.
Ich habe dann den "SpeechSDK51.exe" davon heruntergeladen.
Auf der Seite war "win32all" nicht zu finden
und auf der CD gab es nur diesen exefile: "pywin32-208.win32-py2.4.exe". Ich habe mal angenommen, das er der richtige ist.
Aber weiter bin ich irgendwie nicht gekommen...
Hat zufällig jemand das Buch selbst oder weiß jemand wie man das hinbekommt?
In dem Buch ist das so komisch erklärt
Danke!
Re: SDK 5.1 in Python
Verfasst: Samstag 14. April 2007, 13:00
von Leonidas
Markus12 hat geschrieben:Auf der Seite war "win32all" nicht zu finden
und auf der CD gab es nur diesen exefile: "pywin32-208.win32-py2.4.exe". Ich habe mal angenommen, das er der richtige ist.
Ja, das ist es. win32all wurde irgendwann in pywin32 umbenannt. Kannst du aber auch
von Sourceforge runterladen. Wenn du das installiert hast, hast du dann die PythonWinj IDE und kannst dort das makepy-Utility aufrufen.
Verfasst: Samstag 14. April 2007, 15:55
von Sr4l
habe hier mal etwas code welchen ich mir mal von nem cookbook site kopiert habe, vielleicht auch leich modifiziert bin mir nicht mehr sicher.
http://www.microsoft.com/speech/download/sdk51/
pythonwin muss installiert sein und die Speech API.
Code: Alles auswählen
from win32com.client import constants
import win32com.client
import pythoncom
"""Sample code for using the Microsoft Speech SDK 5.1 via COM in Python.
Requires that the SDK be installed; it's a free download from
http://microsoft.com/speech
and that MakePy has been used on it (in PythonWin,
select Tools | COM MakePy Utility | Microsoft Speech Object Library 5.1).
After running this, then saying "One", "Two", "Three" or "Four" should
display "You said One" etc on the console. The recognition can be a bit
shaky at first until you've trained it (via the Speech entry in the Windows
Control Panel."""
class SpeechRecognition:
""" Initialize the speech recognition with the passed in list of words """
def __init__(self, wordsToAdd):
# For text-to-speech
self.speaker = win32com.client.Dispatch("SAPI.SpVoice")
# For speech recognition - first create a listener
self.listener = win32com.client.Dispatch("SAPI.SpSharedRecognizer")
# Then a recognition context
self.context = self.listener.CreateRecoContext()
# which has an associated grammar
self.grammar = self.context.CreateGrammar()
# Do not allow free word recognition - only command and control
# recognizing the words in the grammar only
self.grammar.DictationSetState(0)
# Create a new rule for the grammar, that is top level (so it begins
# a recognition) and dynamic (ie we can change it at runtime)
self.wordsRule = self.grammar.Rules.Add("wordsRule",
constants.SRATopLevel + constants.SRADynamic, 0)
# Clear the rule (not necessary first time, but if we're changing it
# dynamically then it's useful)
self.wordsRule.Clear()
# And go through the list of words, adding each to the rule
[ self.wordsRule.InitialState.AddWordTransition(None, word) for word in wordsToAdd ]
# Set the wordsRule to be active
self.grammar.Rules.Commit()
self.grammar.CmdSetRuleState("wordsRule", 1)
# Commit the changes to the grammar
self.grammar.Rules.Commit()
# And add an event handler that's called back when recognition occurs
self.eventHandler = ContextEvents(self.context)
# Announce we've started using speech synthesis
self.say("Started successfully")
"""Speak a word or phrase"""
def say(self, phrase):
self.speaker.Speak(phrase)
"""The callback class that handles the events raised by the speech object.
See "Automation | SpSharedRecoContext (Events)" in the MS Speech SDK
online help for documentation of the other events supported. """
class ContextEvents(win32com.client.getevents("SAPI.SpSharedRecoContext")):
"""Called when a word/phrase is successfully recognized -
ie it is found in a currently open grammar with a sufficiently high
confidence"""
def OnRecognition(self, StreamNumber, StreamPosition, RecognitionType, Result):
newResult = win32com.client.Dispatch(Result)
print "You said: ",newResult.PhraseInfo.GetText()
if __name__=='__main__':
wordsToAdd = [ "One", "Two", "Three", "Four", "water", "computer" ]
speechReco = SpeechRecognition(wordsToAdd)
while 1:
pythoncom.PumpWaitingMessages()
Verfasst: Samstag 14. April 2007, 16:29
von jens
Verfasst: Sonntag 15. April 2007, 00:14
von Sr4l
ja ja Google
tut doch mal was gegen die Massenprodukte und nutzt mal Exalead.de
Verfasst: Sonntag 15. April 2007, 11:48
von BlackJack
Tue ich, nicht nur weil ich Google mittlerweile auch für ein wenig zu mächtig halte, sondern weil Exalead wirklich einen Mehrwert gegenüber den Ergebnissen von Google hat. Das weitere Einschränken und das erneute Suchen innerhalb von Suchergebnissen ist echt eine praktische Sache.
http://clusty.com/ ist auch nicht schlecht, die versuchen die Ergebnisse nochmal automatisiert nach Kategorien zu gruppieren.
Verfasst: Sonntag 15. April 2007, 11:55
von Leonidas
BlackJack hat geschrieben:Tue ich, nicht nur weil ich Google mittlerweile auch für ein wenig zu mächtig halte, sondern weil Exalead wirklich einen Mehrwert gegenüber den Ergebnissen von Google hat. Das weitere Einschränken und das erneute Suchen innerhalb von Suchergebnissen ist echt eine praktische Sache.
Muss ich mal ausprobieren. Habe einige Zeit Yahoo benutzt, aber die Suchergebnisse bei Yahoo sind einfach durch die Bank schlechter als bei Google.
Verfasst: Montag 16. April 2007, 15:37
von Markus12
hi,
danke für die links und den code, aber was ist pythonwin genau??
Wird das installiert, wenn man python 2.4 oder 2.5 installiert?
Keine ahnung was das ist
Verfasst: Montag 16. April 2007, 15:55
von gerold
Markus12 hat geschrieben:was ist pythonwin genau??
Wird das installiert, wenn man python 2.4 oder 2.5 installiert?
Hi!
pythonwin ist ein Python-Editor, der bei pywin32 mit dabei ist.
http://sourceforge.net/projects/pywin32/
pywin32 ist eine Erweiterung, die extra installiert werden muss. Damit kann man direkt auf Windows-APIs zugreifen, COM-Server und COM-Clients programmieren und noch so ein paar Dinge. Näheres steht in der Hilfe, die mitinstalliert wird.
mfg
Gerold
Verfasst: Montag 16. April 2007, 16:15
von Markus12
hi,
ich hab nun das richtige pywin32 gedownloaded für 2.5
Dann bin ich auf C:\Python25\Lib\site-packages\pythonwin\Pythonwin.exe gegangen und da hat es folgenden Error gegeben:
Code: Alles auswählen
File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\intpyapp.py", line 171, in InitInstance
import interact
File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\interact.py", line 20, in <module>
import pywin.scintilla.control
File "C:\Python25\Lib\site-packages\pythonwin\pywin\scintilla\control.py", line 12, in <module>
import struct
<type 'exceptions.ImportError'>: No module named struct
Hat das mit dem Speech SDK noch keiner gemacht?
Verfasst: Montag 16. April 2007, 16:52
von BlackJack
Das ist sehr merkwürdig, weil `struct` zur Standardbibliothek gehört. Wenn das nicht importiert werden kann, stimmt etwas mit der Python-Installation nicht.
Verfasst: Montag 16. April 2007, 17:46
von Markus12
Ich hab schon so verdammt viel installiert, darunter auch 2.4 weil das im buch so stand, dass man das brauch
Als ich das SDK 5.1 installiert habe und dann unter Pythonwin bei dem 2.4 gegangen bin, dann kam da nur der SDK 5.0 als ob ich es nicht installiert hätte!
Sollte ich alles mal deinstallieren und einiges neu installieren?
Nebenbei: weiß jeman, ob es schon 2.6 gibt?
Verfasst: Montag 16. April 2007, 19:02
von Leonidas
Markus12 hat geschrieben:Nebenbei: weiß jeman, ob es schon 2.6 gibt?
Von Python? Nein, wird es noch längere Zeit nicht geben. Aber 2.5.1 wird demnächst fertig, der erste RC ist ja schon da.
Verfasst: Montag 16. April 2007, 19:14
von Markus12
Danke
Hat mich weitergebracht!
Verfasst: Montag 16. April 2007, 19:15
von Markus12
Weil ich Pythonwin bei einem Download link für Versionen von 2.3, 2.4, 2.5 und auch für 2.6 gesehen habe
Aber auch gut
Verfasst: Dienstag 17. April 2007, 18:01
von Leonidas
Markus12 hat geschrieben:Weil ich Pythonwin bei einem Download link für Versionen von 2.3, 2.4, 2.5 und auch für 2.6 gesehen habe
Ja, weil pywin32 auch Builds gegen wirklich sehr aktuelle Releases bereitstellt, auch wenn sie noch gar nicht released sind.
Verfasst: Mittwoch 18. April 2007, 16:31
von Markus12
achso