Skip to content

Commit

Permalink
Update mac speech server for Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
tspivey committed Mar 8, 2022
1 parent ecbdeaa commit 83d6506
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 7 additions & 5 deletions mac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python3
#Copyright (C) 2016, 2017 Tyler Spivey
#See the license in COPYING.txt
from Foundation import (
Expand All @@ -7,6 +7,7 @@ from Foundation import (
)
from AppKit import NSSpeechSynthesizer, NSSpeechRecentSyncProperty
from PyObjCTools import AppHelper
from objc import python_method
import threading

rate = None
Expand All @@ -24,6 +25,7 @@ class QueuedSynth(NSObject):
self.handle_index = handler
return self

@python_method
def speak(self, text, index=None):
with self.lock:
self.queue.append((text, index))
Expand Down Expand Up @@ -88,7 +90,7 @@ class FileObserver(NSObject):
else:
self.fileHandle.readInBackgroundAndNotify()
if self.readCallback is not None:
self.readCallback(self, str(newData))
self.readCallback(self, bytes(newData))

def close(self):
self.nc.removeObserver_(self)
Expand All @@ -115,8 +117,8 @@ def gotLine(observer, line):
if not line:
AppHelper.stopEventLoop()
return
line = line.strip('\n')
for l in line.split('\n'):
line = line.strip(b'\n')
for l in line.split(b'\n'):
handle_line(l)

def handle_line(line):
Expand Down Expand Up @@ -146,7 +148,7 @@ def handle_line(line):
volume = str(int(line[1:]) / 100.0)

def gotError(observer, err):
print "error:", err
print("error:", err)
AppHelper.stopEventLoop()

synth = None
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pyte==0.7.0
pyobjc

0 comments on commit 83d6506

Please sign in to comment.