-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Voice): voice support for Windows and macOS
Refactored the entire voice subsystem, now with a generalized API. Added ffplay-static to handle playback on Windows and macOS. Added an option to specify additional ffmpeg args (filters etc.). Linux requires installed ffmpeg, static does not include pulse support. macOS compatibility not tested. Partially resolves issue #10.
- Loading branch information
Garifullin Ruslan
committed
Jan 5, 2021
1 parent
c7bce6b
commit 1b08596
Showing
16 changed files
with
461 additions
and
131 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* eslint-disable global-require */ | ||
import { ID, S16LE_OPTIONS } from './VoiceOptions'; | ||
import { VoiceProvider } from './VoiceProvider'; | ||
|
||
/** | ||
* VoiceProvider for systems on macOS. | ||
* THIS WAS NOT TESTED. I do not have a macOS system to test this | ||
* implementation's behaviour, most likely it's similar to Windows. | ||
* TODO: Input/output devices detection. | ||
*/ | ||
export class DarwinVoiceProvider extends VoiceProvider { | ||
public PLAYBACK_OPTIONS = [...S16LE_OPTIONS, ID.PLAYBACK_OPTIONS, '-']; | ||
|
||
public RECORD_OPTIONS = [ | ||
'-f', | ||
'avfoundation', | ||
'-i', | ||
`"none:${ID.RECORD_DEVICE}"`, | ||
ID.RECORD_OPTIONS, | ||
...S16LE_OPTIONS, | ||
'-', | ||
]; | ||
|
||
public readonly PLAYBACK_DEFAULT_DEVICE = '0'; | ||
|
||
public readonly RECORD_DEFAULT_DEVICE = '0'; | ||
|
||
createPlaybackStream = this.createFFplayPlaybackStream; | ||
|
||
createRecordStream = this.createFFmpegRecordStream; | ||
|
||
getInputDevices = () => ['0']; | ||
|
||
getOutputDevices = () => ['0']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { platform } from 'os'; | ||
import { join } from 'path'; | ||
|
||
export function getFFmpeg() { | ||
if (platform() === 'linux') { | ||
return 'ffmpeg'; | ||
} | ||
|
||
return join(__dirname, `ffmpeg${platform() === 'win32' ? '.exe' : ''}`); | ||
} | ||
|
||
export function getFFplay() { | ||
return join(__dirname, `ffplay${platform() === 'win32' ? '.exe' : ''}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { execSync } from 'child_process'; | ||
import { createLogger } from '../Console'; | ||
import { ID, S16LE_OPTIONS } from './VoiceOptions'; | ||
import { VoiceProvider } from './VoiceProvider'; | ||
|
||
const { error } = createLogger('LinuxVoiceProvider'); | ||
|
||
/** | ||
* VoiceProvider for systems on Linux with PulseAudio support. | ||
*/ | ||
export class LinuxVoiceProvider extends VoiceProvider { | ||
public PLAYBACK_OPTIONS = [ | ||
...S16LE_OPTIONS, | ||
ID.PLAYBACK_OPTIONS, | ||
'-i', | ||
'-', | ||
'-f', | ||
'pulse', | ||
'-buffer_duration', | ||
'5', | ||
'-name', | ||
ID.APP_NAME, | ||
ID.PLAYBACK_DEVICE, | ||
]; | ||
|
||
public RECORD_OPTIONS = [ | ||
'-f', | ||
'pulse', | ||
'-name', | ||
ID.APP_NAME, | ||
'-i', | ||
ID.RECORD_DEVICE, | ||
ID.RECORD_OPTIONS, | ||
...S16LE_OPTIONS, | ||
'-', | ||
]; | ||
|
||
public readonly PLAYBACK_DEFAULT_DEVICE = 'default'; | ||
|
||
public readonly RECORD_DEFAULT_DEVICE = 'default'; | ||
|
||
createPlaybackStream = this.createFFmpegPlaybackStream; | ||
|
||
createRecordStream = this.createFFmpegRecordStream; | ||
|
||
getInputDevices = () => { | ||
try { | ||
const sourcesOut = execSync('pactl list sources short').toString(); | ||
const sources = sourcesOut | ||
.split('\n') | ||
.map((value) => value.split('\t')[1]) | ||
.filter((value) => value); | ||
|
||
return sources; | ||
} catch (e) { | ||
error(e); | ||
|
||
return [this.RECORD_DEFAULT_DEVICE]; | ||
} | ||
}; | ||
|
||
getOutputDevices = () => { | ||
try { | ||
const sinksOut = execSync('pactl list sinks short').toString(); | ||
const sinks = sinksOut | ||
.split('\n') | ||
.map((value) => value.split('\t')[1]) | ||
.filter((value) => value); | ||
|
||
return sinks; | ||
} catch (e) { | ||
error(e); | ||
|
||
return [this.PLAYBACK_DEFAULT_DEVICE]; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Writable } from 'stream'; | ||
|
||
export type PlaybackStream = { | ||
stream: Writable; | ||
device: string; | ||
end(): void; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Readable } from 'stream'; | ||
|
||
export type RecordStream = { | ||
stream: Readable; | ||
device: string; | ||
end(): void; | ||
}; |
Oops, something went wrong.