expo-speech-recognition 3.1.1 → 3.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # expo-speech-recognition
2
2
 
3
+ ## 3.1.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 8c06f3e: Removed tvOS from the podspec, as Speech API is not available there
8
+
9
+ ## 3.1.2
10
+
11
+ ### Patch Changes
12
+
13
+ - 5f3bd93: Avoid restarting the iOS audio engine during audio route changes while the app
14
+ is leaving the foreground, which could still crash some speech-recognition
15
+ sessions after the 3.1.1 input-node readiness fix.
16
+
3
17
  ## 3.1.1
4
18
 
5
19
  ### Patch Changes
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
10
10
  s.license = package['license']
11
11
  s.author = package['author']
12
12
  s.homepage = package['homepage']
13
- s.platforms = { :ios => '13.4', :tvos => '13.4' }
13
+ s.platforms = { :ios => '13.4' }
14
14
  s.swift_version = '5.4'
15
15
  s.source = { git: 'https://github.com/jamsch/expo-speech-recognition' }
16
16
  s.static_framework = true
@@ -2,6 +2,7 @@ import AVFoundation
2
2
  import Accelerate
3
3
  import Foundation
4
4
  import Speech
5
+ import UIKit
5
6
 
6
7
  enum RecognizerError: Error {
7
8
  case nilRecognizer
@@ -744,19 +745,30 @@ actor ExpoSpeechRecognizer: ObservableObject {
744
745
  object: AVAudioSession.sharedInstance(),
745
746
  queue: .main
746
747
  ) { [weak self] _ in
748
+ let appState = UIApplication.shared.applicationState
747
749
  Task { [weak self] in
748
750
  let taskState = await self?.task?.state
749
- await self?.handleAudioRouteChange(taskState: taskState)
751
+ await self?.handleAudioRouteChange(taskState: taskState, appState: appState)
750
752
  }
751
753
  }
752
754
 
753
755
  }
754
756
 
755
757
  private func handleAudioRouteChange(
756
- taskState: SFSpeechRecognitionTaskState?
758
+ taskState: SFSpeechRecognitionTaskState?,
759
+ appState: UIApplication.State
757
760
  ) {
758
761
  // We only care about route changes when the recognizer is active
759
762
  if taskState == .running || taskState == .starting {
763
+ // App deactivation can emit a route change while the audio session is
764
+ // being torn down. In that case we should stop recognition instead of
765
+ // trying to reconnect the engine again.
766
+ guard appState == .active else {
767
+ emitError(.audioSessionInterrupted)
768
+ stopListening()
769
+ reset(andEmitEnd: true)
770
+ return
771
+ }
760
772
  guard !restartAudioEngineForRouteChange() else {
761
773
  return
762
774
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-speech-recognition",
3
- "version": "3.1.1",
3
+ "version": "3.1.3",
4
4
  "description": "Speech Recognition for React Native Expo projects",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",