Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(punctuation): handle punctuation #74

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ SpeechRecognition.available();
* prompt - prompt message to display on popup (Android only)
* partialResults - return partial results if found
* popup - display popup window when listening for utterance (Android only)
* addPunctuation - enable punctuation (IOS only for now)
* If partialResults is true, the function respond directly without result and event `partialResults` will be emit for each partial result, until stopped.
* @returns void
*/
Expand All @@ -85,6 +86,7 @@ SpeechRecognition.start({
prompt: "Say something",
partialResults: true,
popup: true,
addPunctuation: true,
});
// listen to partial results
SpeechRecognition.addListener("partialResults", (data: any) => {
Expand Down
5 changes: 5 additions & 0 deletions ios/Plugin/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class SpeechRecognition: CAPPlugin {
let language: String = call.getString("language") ?? "en-US"
let maxResults : Int = call.getInt("maxResults") ?? self.DEFAULT_MATCHES
let partialResults : Bool = call.getBool("partialResults") ?? false
let addPunctuation : Bool = call.getBool("addPunctuation") ?? false

if (self.recognitionTask != nil) {
self.recognitionTask?.cancel()
Expand All @@ -77,6 +78,10 @@ public class SpeechRecognition: CAPPlugin {
self.recognitionRequest = SFSpeechAudioBufferRecognitionRequest()
self.recognitionRequest?.shouldReportPartialResults = partialResults

if #available(iOS 16.0, *) {
self.recognitionRequest?.addsPunctuation = addPunctuation
}

let inputNode: AVAudioInputNode = self.audioEngine!.inputNode
let format: AVAudioFormat = inputNode.outputFormat(forBus: 0)

Expand Down
1 change: 1 addition & 0 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ export interface UtteranceOptions {
prompt?: string;
popup?: boolean;
partialResults?: boolean;
addPunctuation?: boolean;
}