Skip to content

Prefetch audio instructions#724

Merged
bsudekum merged 6 commits into
masterfrom
prefetch
Oct 19, 2017
Merged

Prefetch audio instructions#724
bsudekum merged 6 commits into
masterfrom
prefetch

Conversation

@bsudekum
Copy link
Copy Markdown
Contributor

Prerequisite #614

It's relatively dumb right now, when we fire the notification to say something:

  1. Check if the instruction is a key on RouteProgress.spokenInstructionsForRoute and has data.
  2. If so, use this data to give the instruction
  3. If not, first say the instruction using the normal methods
  4. After we say it, we then look and see if the user has any upcoming steps
  5. If so, get all instructions for step, download the data and add it to RouteProgress.spokenInstructionsForRoute
  6. Repeat

/cc @1ec5 @frederoni @ericrwolfe @JThramer

}
}

public var spokenInstructionsForRoute: [String: Data] = [:]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this to the PollyVoiceController?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I guess it doesn’t need to be stored on routeprogress

@bsudekum bsudekum changed the base branch from voice-instructions to master October 18, 2017 21:14
@bsudekum bsudekum changed the base branch from master to voice-instructions October 18, 2017 21:16
@bsudekum bsudekum changed the base branch from voice-instructions to master October 18, 2017 21:16
@bsudekum
Copy link
Copy Markdown
Contributor Author

@1ec5 @frederoni could I get another review?

for (stepIndex, step) in routeProgresss.currentLegProgress.leg.steps.suffix(from: routeProgresss.currentLegProgress.stepIndex).enumerated() {
let adjustedStepIndex = stepIndex + routeProgresss.currentLegProgress.stepIndex

guard adjustedStepIndex < routeProgresss.currentLegProgress.stepIndex + 3 else { continue }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be using the stepsAheadToCache instead of 3?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yep.

}
}

func sayInStruction(for data: Data) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: s/InSt/Inst

@bsudekum bsudekum merged commit 3b1dac2 into master Oct 19, 2017
@bsudekum bsudekum deleted the prefetch branch October 19, 2017 21:05
/**
Number of steps ahead of the current step to cache spoken instructions.
*/
public var stepsAheadToCache: Int = 3
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • “Caching” implies reusing things after the first time they’re needed. A more appropriate word for this feature is “prefetching”.
  • The name of this property talks about steps instead of spoken instructions – are we fetching individual steps from the Directions API and caching them now?
  • By beginning a name with a plural noun, you’re implying a type of Array.

How about countOfStepsForPrefetchingInstructions?

var cacheURLSession: URLSession
var cachePollyTask: URLSessionDataTask?

var spokenInstructionsForRoute: [String: Data] = [:]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use an NSCache instead of a dictionary: #759.

guard let instructions = step.instructionsSpokenAlongStep else { continue }

for instruction in instructions {
guard spokenInstructionsForRoute[instruction.ssmlText] == nil else { continue }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be written more clearly as:

for instruction in instructions where spokenInstructionsForRoute[instruction.ssmlText] != nil {  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants