alphacep / alphacep/vosk-api

iOS: Audio decoding restricted to microphone input source only

Ouverte
#2,017 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Jupyter Notebook
Étoiles
15.1k
Forks
1.8k
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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
})
```

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.