Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
appinventor-sources
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
appinventor-sources
Commits
058782e5
Commit
058782e5
authored
Oct 12, 2023
by
Evan W. Patton
Committed by
Evan W. Patton
Oct 16, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix lack of lifecycle management in TextToSpeech on iOS
Change-Id: Ib8732739e437f3aa32f6203589cc9e6e9fb30228
parent
96ff61f0
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
7 deletions
+53
-7
appinventor/aicompanionapp/src/ViewController.swift
appinventor/aicompanionapp/src/ViewController.swift
+18
-0
appinventor/components-ios/src/Form.swift
appinventor/components-ios/src/Form.swift
+4
-0
appinventor/components-ios/src/NonvisibleComponent.swift
appinventor/components-ios/src/NonvisibleComponent.swift
+2
-0
appinventor/components-ios/src/TextToSpeech.swift
appinventor/components-ios/src/TextToSpeech.swift
+29
-7
No files found.
appinventor/aicompanionapp/src/ViewController.swift
View file @
058782e5
...
...
@@ -72,6 +72,7 @@ public class ViewController: UINavigationController, UITextFieldDelegate {
SCMInterpreter
.
shared
.
protect
(
self
)
ViewController
.
controller
=
self
NotificationCenter
.
default
.
addObserver
(
self
,
selector
:
#selector(
settingsChanged(_:)
)
,
name
:
UserDefaults
.
didChangeNotification
,
object
:
nil
)
self
.
delegate
=
self
}
@objc
func
settingsChanged
(
_
sender
:
AnyObject
?)
{
...
...
@@ -386,3 +387,20 @@ public class ViewController: UINavigationController, UITextFieldDelegate {
}
}
}
extension
ViewController
:
UINavigationControllerDelegate
{
public
func
navigationController
(
_
navigationController
:
UINavigationController
,
animationControllerFor
operation
:
UINavigationController
.
Operation
,
from
fromVC
:
UIViewController
,
to
toVC
:
UIViewController
)
->
UIViewControllerAnimatedTransitioning
?
{
guard
let
oldForm
=
fromVC
as?
Form
,
let
newForm
=
toVC
as?
Form
else
{
return
nil
}
oldForm
.
onPause
()
if
operation
==
.
pop
{
oldForm
.
onDestroy
()
}
newForm
.
onResume
()
return
nil
}
}
appinventor/components-ios/src/Form.swift
View file @
058782e5
...
...
@@ -167,6 +167,10 @@ let kMinimumToastWait = 10.0
view
.
accessibilityIdentifier
=
String
(
describing
:
type
(
of
:
self
))
}
open
func
add
(
_
component
:
NonvisibleComponent
)
{
_components
.
append
(
component
)
}
open
func
add
(
_
component
:
ViewComponent
)
{
_components
.
append
(
component
)
_linearView
.
addItem
(
LinearViewItem
(
component
.
view
))
...
...
appinventor/components-ios/src/NonvisibleComponent.swift
View file @
058782e5
...
...
@@ -10,6 +10,8 @@ open class NonvisibleComponent: NSObject, Component {
@objc
public
init
(
_
container
:
ComponentContainer
)
{
self
.
_form
=
container
.
form
super
.
init
()
_form
?
.
add
(
self
)
}
open
func
copy
(
with
zone
:
NSZone
?
=
nil
)
->
Any
{
...
...
appinventor/components-ios/src/TextToSpeech.swift
View file @
058782e5
...
...
@@ -163,15 +163,17 @@ open class TextToSpeech: NonvisibleComponent, AVSpeechSynthesizerDelegate {
// MARK: Methods
@objc
open
func
Speak
(
_
message
:
String
)
throws
{
BeforeSpeaking
()
try
AVAudioSession
.
sharedInstance
()
.
setCategory
(
AVAudioSession
.
Category
.
playback
)
try
AVAudioSession
.
sharedInstance
()
.
setActive
(
true
)
DispatchQueue
.
main
.
async
{
self
.
BeforeSpeaking
()
let
utterance
=
AVSpeechUtterance
(
string
:
message
)
utterance
.
pitchMultiplier
=
_pitch
utterance
.
rate
=
_speechRate
utterance
.
voice
=
_voice
_tts
.
stopSpeaking
(
at
:
AVSpeechBoundary
.
immediate
)
_tts
.
speak
(
utterance
)
utterance
.
pitchMultiplier
=
self
.
_pitch
utterance
.
rate
=
self
.
_speechRate
utterance
.
voice
=
self
.
_voice
self
.
_tts
.
stopSpeaking
(
at
:
AVSpeechBoundary
.
immediate
)
self
.
_tts
.
speak
(
utterance
)
}
}
@objc
open
func
Stop
()
{
...
...
@@ -214,3 +216,23 @@ open class TextToSpeech: NonvisibleComponent, AVSpeechSynthesizerDelegate {
}
}
}
extension
TextToSpeech
:
LifecycleDelegate
{
public
func
onResume
()
{
if
_tts
.
isPaused
{
_tts
.
continueSpeaking
()
}
}
public
func
onPause
()
{
_tts
.
pauseSpeaking
(
at
:
.
immediate
)
}
public
func
onDestroy
()
{
Stop
()
}
public
func
onDelete
()
{
Stop
()
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment