diff --git a/conformance/voice/pronunciations-bad-params.jsonl b/conformance/voice/pronunciations-bad-params.jsonl new file mode 100644 index 0000000..0b586d4 --- /dev/null +++ b/conformance/voice/pronunciations-bad-params.jsonl @@ -0,0 +1,15 @@ +{"session": "pronunciations-bad-params", "description": "a pronunciation whose word or ipa is empty or holds a space or a line break is InvalidParams in voice/speak, whether or not the models are ready (spec 8)", "requires": ["voice", "voice.pronunciations", "voice.speak"]} +{"send": {"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocol": "1.0", "client": {"name": "cnp-conformance", "version": "1.0"}}}} +{"expect": {"id": 1, "result": {"protocol": "1.0", "node": {"name": "$string", "version": "$string", "license": "$string"}, "capabilities": "$object"}}} +{"send": {"jsonrpc": "2.0", "id": 2, "method": "voice/speak", "params": {"text": "Knight to f3.", "pronunciations": [{"word": "", "ipa": "naɪt"}]}}} +{"expect": {"id": 2, "error": {"code": -32602, "message": "$string"}}} +{"send": {"jsonrpc": "2.0", "id": 3, "method": "voice/speak", "params": {"text": "Knight to f3.", "pronunciations": [{"word": "knight", "ipa": ""}]}}} +{"expect": {"id": 3, "error": {"code": -32602, "message": "$string"}}} +{"send": {"jsonrpc": "2.0", "id": 4, "method": "voice/speak", "params": {"text": "Knight to f3.", "pronunciations": [{"word": "two words", "ipa": "naɪt"}]}}} +{"expect": {"id": 4, "error": {"code": -32602, "message": "$string"}}} +{"send": {"jsonrpc": "2.0", "id": 5, "method": "voice/speak", "params": {"text": "Knight to f3.", "pronunciations": [{"word": "knight", "ipa": "na\nɪt"}]}}} +{"expect": {"id": 5, "error": {"code": -32602, "message": "$string"}}} +{"send": {"jsonrpc": "2.0", "id": 99, "method": "shutdown"}} +{"expect": {"id": 99, "result": null}} +{"send": {"jsonrpc": "2.0", "method": "exit"}} +{"expectExit": 0} diff --git a/crates/cnp/src/voice.rs b/crates/cnp/src/voice.rs index 2b4b5da..9c68562 100644 --- a/crates/cnp/src/voice.rs +++ b/crates/cnp/src/voice.rs @@ -38,6 +38,15 @@ //! "night". The client knows its domain, so the node needn't: a chess board sends the words //! of a move, another program its own. //! +//! ## Pronunciations +//! +//! A client that knows how a word is said, and a node's model might not (a player's name, an +//! opening's), gives it with `voice/speak` as [`Pronunciation`]s (capability `pronunciations`): +//! the word and its sounds in the International Phonetic Alphabet. The node says that word as +//! given, wherever it appears in the text. Each request carries its own, as it does hotwords, +//! so a request stands alone, and the node keeps no list between requests. A node that can't +//! say an entry's sounds ignores that entry rather than fail the speech. +//! //! A node downloads and loads its own models, and says how far it has got //! with `voice/modelState`; until a model is ready, requests that need it are answered with //! [`code::NOT_READY`](crate::code::NOT_READY). @@ -71,6 +80,9 @@ pub struct VoiceCapabilities { /// What is said so far, while it is still being said (`voice/hearing`, `partialMs`). #[serde(default)] pub partials: bool, + /// Words whose sounds the client gives, in `voice/speak` (`pronunciations`). + #[serde(default)] + pub pronunciations: bool, /// The audio formats it reads and writes. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub formats: Vec, @@ -146,6 +158,23 @@ pub struct SpeakParams { /// Whether to return each word's start and end (capability `wordTimes`). #[serde(default, skip_serializing_if = "is_false")] pub word_times: bool, + /// How words in `text` are said (capability `pronunciations`). Missing: none. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub pronunciations: Vec, +} + +/// How one word is said: the word, and its sounds in the International Phonetic Alphabet. +/// +/// The node matches `word` in the text without regard to case, whole words only, and says +/// `ipa` for it. Stress marks (`ˈ`, `ˌ`) and length marks are part of the notation; spaces are +/// not allowed in either field. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Pronunciation { + /// The word as it is written in the text, with no spaces: "Nimzowitsch". + pub word: String, + /// Its sounds in IPA, with no spaces: "ˈnɪmzoʊˌvɪtʃ". + pub ipa: String, } /// The speech. diff --git a/crates/cnp/tests/messages.rs b/crates/cnp/tests/messages.rs index f0e39a0..b991c22 100644 --- a/crates/cnp/tests/messages.rs +++ b/crates/cnp/tests/messages.rs @@ -160,6 +160,37 @@ fn a_listen_and_its_audio_leave_out_what_isnt_said() { ); } +#[test] +fn a_speak_request_gives_pronunciations_only_when_it_has_some() { + let plain = voice::SpeakParams { + text: "Knight to f3.".into(), + voice: None, + speed: None, + format: None, + word_times: false, + pronunciations: Vec::new(), + }; + assert_eq!( + serde_json::to_value(&plain).unwrap(), + json!({"text": "Knight to f3."}) + ); + let said = voice::SpeakParams { + pronunciations: vec![voice::Pronunciation { + word: "Nimzowitsch".into(), + ipa: "ˈnɪmzoʊˌvɪtʃ".into(), + }], + ..plain + }; + let value = serde_json::to_value(&said).unwrap(); + assert_eq!( + value["pronunciations"], + json!([{"word": "Nimzowitsch", "ipa": "ˈnɪmzoʊˌvɪtʃ"}]) + ); + // And a node that doesn't know the field reads the request as a plain one. + let back: voice::SpeakParams = serde_json::from_value(value).unwrap(); + assert_eq!(back, said); +} + #[test] fn a_method_without_params_sends_none_and_reads_none() { let request = Request::new::(1, &NoParams); diff --git a/spec/cnp.md b/spec/cnp.md index a3ff6dd..64ca900 100644 --- a/spec/cnp.md +++ b/spec/cnp.md @@ -847,6 +847,7 @@ Capabilities: | `wordTimes` | boolean | Each word's start and end, in either direction | | `hotwords` | boolean | Words the client expects to be said, favoured in what is heard (`hotwords`, below) | | `partials` | boolean | `voice/hearing`: what is said so far, while it is still being said (`partialMs`, below) | +| `pronunciations` | boolean | Words whose sounds the client gives, in `voice/speak` (`pronunciations`, below) | | `formats` | array of strings | The audio formats it reads and writes | Audio formats: @@ -861,6 +862,18 @@ product's names) MAY give them with `voice/transcribe` and `voice/listen`, if th or holds a line break is `InvalidParams`, and a node MAY refuse more hotwords than it can take the same way. A node without `hotwords` ignores them. +**Pronunciations.** A client that knows how a word is said, and the node's model may not (a +player's name, an opening's), MAY give it with `voice/speak`, if the node offers +`pronunciations`: an array of `{"word", "ipa"}`, the word as written in the text and its sounds +in the [International Phonetic Alphabet](https://www.internationalphoneticassociation.org/), +with stress and length marks, such as `ˈ` and `ˌ`. The node says that word as given wherever it +appears in `text`, matching whole words without regard to case. Each request carries its own, +so a request stands alone and the node keeps nothing between requests. A `word` or an `ipa` that +is empty or holds a space or a line break is `InvalidParams`, and a node MAY refuse more entries +than it can take the same way. A node that has no phoneme for a symbol in an entry's `ipa` +ignores that entry, so one entry never silences a reply. A node without `pronunciations` +ignores them all. + The voice domain stands on its own: a voice node needs only this section, the lifecycle ([5](#5-lifecycle)) and the errors ([9](#9-errors)), and none of the engine domain. [audio-chat-box](https://github.com/cjus/audio-chat-box), the voice node Solrac uses, @@ -887,8 +900,9 @@ Params: | `speed` | number | 1.0 is the voice's own pace | | `format` | string | The audio format wanted. Missing: `wav` | | `wordTimes` | boolean | Return each word's start and end, if the model can tell (needs `wordTimes`) | +| `pronunciations` | array | How words in `text` are said: each `word` and its `ipa` (needs `pronunciations`, above). Missing: none | -An unknown voice is `InvalidParams`. The result: +An unknown voice, or a pronunciation that is malformed, is `InvalidParams`. The result: | Field | Type | | | --- | --- | --- | @@ -905,6 +919,12 @@ The audio is shortened here: ← {"jsonrpc": "2.0", "id": 20, "result": {"format": "pcmF32", "sampleRate": 24000, "audio": "AAAAAAAAAAA=", "durationMs": 1150, "words": [{"text": "Knight", "startMs": 40, "endMs": 390}, {"text": "to", "startMs": 390, "endMs": 520}, {"text": "f3", "startMs": 520, "endMs": 1100}]}} ``` +A name the model would get wrong, said as given: + +```cnp +→ {"jsonrpc": "2.0", "id": 21, "method": "voice/speak", "params": {"text": "Nimzowitsch played the Sveshnikov.", "pronunciations": [{"word": "Nimzowitsch", "ipa": "ˈnɪmzoʊˌvɪtʃ"}, {"word": "Sveshnikov", "ipa": "ˈsvɛʃnəˌkɔv"}]}} +``` + ### 8.3 `voice/transcribe` Params: @@ -1085,6 +1105,11 @@ These names are reserved, so that nothing else uses them: ## 14. Changes +- **1.0 (draft), 2026-11-11**, added to the draft: **pronunciations** (capability + `pronunciations` and `voice/speak`'s `pronunciations`), so a client can say how a word the + node's model may get wrong is said, in IPA, rather than the voice node knowing a client's + names. Optional: a node that doesn't offer it, or a request that doesn't send it, is unchanged + (cjus/chessgui#539). - **1.0 (draft), 2026-11-08**, added to the draft: **live partials** (capability `partials`, a listen's `partialMs` and the notification `voice/hearing`), so a client can show a player's words as they are said. All optional: a node that doesn't offer it, or a listen that doesn't