mirror of
https://github.com/linux-speakup/espeakup.git
synced 2026-08-22 23:54:17 +02:00
Add --volume option
This adds the command-line option to set the volume via --volume=N When --volume is specified, the volume is locked using a new volumeSet flag to prevent it from being overridden by runtime commands (e.g. from the kernel). volumeMultiplier was also changed from 22 to 16, which maps the default volume to ~100%, keeping the volume consistent when --volume isn't provided
This commit is contained in:
parent
fa848f509e
commit
8899405c9a
2 changed files with 25 additions and 3 deletions
13
src/cli.c
13
src/cli.c
|
|
@ -35,11 +35,15 @@ extern char *defaultVoice;
|
|||
/* Whether to drive ALSA volume */
|
||||
extern int alsaVolume;
|
||||
|
||||
/* default volume */
|
||||
extern int defaultVolume;
|
||||
extern int volumeSet;
|
||||
/* command line options */
|
||||
const char *shortOptions = "P:V:adhv";
|
||||
const struct option longOptions[] = {
|
||||
{"pid-path", required_argument, NULL, 'P'},
|
||||
{"default-voice", required_argument, NULL, 'V'},
|
||||
{"volume", required_argument, NULL, 'x'},
|
||||
{"alsa-volume", no_argument, &alsaVolume, 1},
|
||||
{"acsint", no_argument, NULL, 'a'},
|
||||
{"debug", no_argument, NULL, 'd'},
|
||||
|
|
@ -57,6 +61,7 @@ static void show_help()
|
|||
printf(" --debug, -d\t\t\t\tDebug mode (stay in the foreground).\n");
|
||||
printf(" --help, -h\t\t\t\tShow this help.\n");
|
||||
printf(" --version, -v\t\t\t\tDisplay the software version.\n");
|
||||
printf(" --volume=[1-150]\t\t\tSet the volume of speakup.\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
|
@ -95,6 +100,14 @@ void process_cli(int argc, char **argv)
|
|||
case 'v':
|
||||
show_version();
|
||||
break;
|
||||
case 'x':
|
||||
volumeSet = 1;
|
||||
defaultVolume = atoi(optarg);
|
||||
if (defaultVolume < 1 || defaultVolume > 150) {
|
||||
fprintf(stderr, "WARNING: Volume must be between 1 and 150\n");
|
||||
volumeSet = 0;
|
||||
}
|
||||
break;
|
||||
case -1:
|
||||
case 0:
|
||||
break;
|
||||
|
|
|
|||
15
src/espeak.c
15
src/espeak.c
|
|
@ -32,7 +32,8 @@ const int defaultFrequency = 5;
|
|||
const int defaultPitch = 5;
|
||||
const int defaultRange = 5;
|
||||
const int defaultRate = 2;
|
||||
const int defaultVolume = 5;
|
||||
int defaultVolume = 5;
|
||||
int volumeSet = 0;
|
||||
char *defaultVoice = NULL;
|
||||
int alsaVolume = 0;
|
||||
|
||||
|
|
@ -42,7 +43,7 @@ const int pitchMultiplier = 11;
|
|||
const int rangeMultiplier = 11;
|
||||
const int rateMultiplier = 41;
|
||||
const int rateOffset = 80;
|
||||
const int volumeMultiplier = 22;
|
||||
const int volumeMultiplier = 16;
|
||||
|
||||
volatile int stop_requested = 0;
|
||||
int paused_espeak = 1;
|
||||
|
|
@ -246,11 +247,19 @@ static espeak_ERROR set_volume(struct synth_t *s, int vol, enum adjust_t adj)
|
|||
{
|
||||
espeak_ERROR rc;
|
||||
|
||||
|
||||
if (adj == ADJ_DEC)
|
||||
vol = -vol;
|
||||
if (adj != ADJ_SET)
|
||||
vol += s->volume;
|
||||
rc = espeak_SetParameter(espeakVOLUME, (vol + 1) * volumeMultiplier, 0);
|
||||
|
||||
/* use the volume if specified by the user */
|
||||
if (volumeSet) {
|
||||
rc = espeak_SetParameter(espeakVOLUME, defaultVolume, 0);
|
||||
}
|
||||
else {
|
||||
rc = espeak_SetParameter(espeakVOLUME, (vol + 1) * volumeMultiplier, 0);
|
||||
}
|
||||
if (rc == EE_OK) {
|
||||
s->volume = vol;
|
||||
if (alsaVolume)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue