Skip to content

Module speechlight.darwin

Darwin speech.

Class Speech(BaseSpeech)

Implements Speech for Darwin.

Source code in speechlight/darwin.py
class Speech(BaseSpeech):
	"""Implements Speech for Darwin."""

	_darwin: Optional[Any] = None

	def __init__(self) -> None:  # pragma: no cover
		"""Defines the constructor."""
		# Allocate and initialize the default TTS.
		if sys.platform == "darwin":
			self._darwin = NSSpeechSynthesizer.alloc().init()

	def braille(self, text: str) -> None:  # NOQA: D102
		pass

	def output(self, text: str, *, interrupt: bool = False) -> None:  # NOQA: D102
		self.say(text, interrupt=interrupt)
		self.braille(text)

	def say(self, text: str, *, interrupt: bool = False) -> None:  # NOQA: D102
		if self._darwin is not None:
			if interrupt:
				self.silence()
			self._darwin.startSpeakingString_(text)

	def silence(self) -> None:  # NOQA: D102
		if self._darwin is not None:
			self._darwin.stopSpeaking()

	def speaking(self) -> bool:  # NOQA: D102
		status = False
		if self._darwin is not None:
			status = bool(self._darwin.isSpeaking())
		return status

Method __init__(self) special

Defines the constructor.

Source code in speechlight/darwin.py
def __init__(self) -> None:  # pragma: no cover
	"""Defines the constructor."""
	# Allocate and initialize the default TTS.
	if sys.platform == "darwin":
		self._darwin = NSSpeechSynthesizer.alloc().init()

Method braille(self, text)

Brailles text.

Parameters:

Name Type Description Default
text str

The text to be brailled.

required
Source code in speechlight/darwin.py
def braille(self, text: str) -> None:  # NOQA: D102
	pass

Method output(self, text, *, interrupt=False)

Speaks and brailles text.

Parameters:

Name Type Description Default
text str

The output text.

required
interrupt bool

True if the speech should be silenced before speaking.

False
Source code in speechlight/darwin.py
def output(self, text: str, *, interrupt: bool = False) -> None:  # NOQA: D102
	self.say(text, interrupt=interrupt)
	self.braille(text)

Method say(self, text, *, interrupt=False)

Speaks text.

Parameters:

Name Type Description Default
text str

The text to be spoken.

required
interrupt bool

True if the speech should be silenced before speaking.

False
Source code in speechlight/darwin.py
def say(self, text: str, *, interrupt: bool = False) -> None:  # NOQA: D102
	if self._darwin is not None:
		if interrupt:
			self.silence()
		self._darwin.startSpeakingString_(text)

Method silence(self)

Cancels speech and flushes the speech buffer.

Source code in speechlight/darwin.py
def silence(self) -> None:  # NOQA: D102
	if self._darwin is not None:
		self._darwin.stopSpeaking()

Method speaking(self)

Determines if text is currently being spoken.

Returns:

Type Description
bool

True if text is currently being spoken, False otherwise.

Source code in speechlight/darwin.py
def speaking(self) -> bool:  # NOQA: D102
	status = False
	if self._darwin is not None:
		status = bool(self._darwin.isSpeaking())
	return status