alphacep / alphacep/vosk-api

iOS: Audio decoding restricted to microphone input source only

Aperta
#2,017 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Jupyter Notebook
Stelle
15.1k
Fork
1.8k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

An iOS app uses a WKWebView inside a UIViewController to run a web-based game within my app (Swift framework).

**Requirements**
• Vosk must recognise only the input source as mic only.
• Vosk must not detect or transcribe any audio coming from the game inside the WKWebView. **(WKWebView used in my app. Not other app)**

For example, Vosk should not transcribe the WKWebView audio (game sounds, music, voice, etc.). It should only process the user’s spoken voice from the mic input and send that mic audio to the vosk speech decoder.

**Question**

How can I modify my iOS Swift code to make Vosk listen only to the microphone and ignore the WKWebView/game audio?

Note: This is required for an iOS app.

**Code:**

```
// Create the audio engine
self.audioEngine = AVAudioEngine()

// Get the microphone input node + its format
let inputNode = audioEngine?.inputNode
let inputFormat = inputNode?.inputFormat(forBus: 0)
let pcmFormat = AVAudioFormat.init(
commonFormat: AVAudioCommonFormat.pcmFormatInt16,
sampleRate: inputFormat?.sampleRate ?? 0.0,
channels: 1,
interleaved: true
)

// Load/create the Vosk model
let model = VoskModel()
guard var words = words?.map({ $0.lowercased() }), !words.isEmpty else {
throw RecognizerError.noAnswersProvided
}

// Vosk recognizer
guard let recognizer = Vosk(model: model, sampleRate: Float(inputFormat?.sampleRate ?? 0.0), wordsJSON: wordsJSON) else {
throw RecognizerError.recognizerIsUnavailable
}

// Install a “tap” on the mic input node
inputNode?.installTap(
onBus: 0,
bufferSize: UInt32((inputFormat?.sampleRate ?? 0.0) / 20),
format: pcmFormat
) { [weak self] buffer, time in
// result
})
```

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.