语音合成&语音识别

用微软语音合成功能生成xiaoxiao的语音。

用Whisper离线识别合成的语音输出srt字幕。

一、语音合成

参考这个网址:https://www.bilibili.com/read/cv19064633

合成的音频:晓晓朗读-温柔

二、Whisper 语音识别

下载模型后放入程序目录下:

请注意,主要示例目前仅使用 16 位 WAV 文件运行,因此请确保在运行该工具之前转换您的输入。例如,您可以像这样使用 ffmpeg:

./ffmpeg.exe -i 女孩向男孩表白话-温柔.mp3 -ar 16000 -ac 1 -c:a pcm_s16le 女孩向男孩表白话-温柔.wav

修改示例代码的默认设置:

运行程序,识别结果输出到控制台,也可输出到srt字幕文本:

语音识别视频演示

参考:

模型下载地址:

https://github.com/ggerganov/whisper.cpp/tree/master/models

whisper的C#Demo:

https://github.com/sandrohanea/whisper.net

附录-语音识别结果输出到控制台:

whisper_init_from_file_no_state: loading model from 'ggml-base.bin'whisper_model_load: loading modelwhisper_model_load: n_vocab = 51865whisper_model_load: n_audio_ctx = 1500whisper_model_load: n_audio_state = 512whisper_model_load: n_audio_head= 8whisper_model_load: n_audio_layer = 6whisper_model_load: n_text_ctx= 448whisper_model_load: n_text_state= 512whisper_model_load: n_text_head = 8whisper_model_load: n_text_layer= 6whisper_model_load: n_mels= 80whisper_model_load: f16 = 1whisper_model_load: type= 2whisper_model_load: mem required=215.00 MB (+6.00 MB per decoder)whisper_model_load: adding 1608 extra tokenswhisper_model_load: model ctx =140.60 MBwhisper_model_load: model size=140.54 MBwhisper_init_state: kv self size=5.25 MBwhisper_init_state: kv cross size = 17.58 MBwhisper_full_with_state: auto-detected language: zh (p = 0.999260)New Segment: 00:00:00 ==> 00:00:04.0800000 : 曾经我以为这一辈子我都不会再遇到喜欢的人New Segment: 00:00:04.0800000 ==> 00:00:07.0400000 : 直到遇见你那种心动的感觉New Segment: 00:00:07.0400000 ==> 00:00:10.3200000 : 我想控制 想忘记 却无能为力New Segment: 00:00:10.3200000 ==> 00:00:12.2800000 : 与你相处的时间越久New Segment: 00:00:12.2800000 ==> 00:00:13.9200000 : 对你的喜欢就越深New Segment: 00:00:13.9200000 ==> 00:00:15.3200000 : 感觉就越强烈New Segment: 00:00:15.3200000 ==> 00:00:16.8800000 : 你会不会跟我一样New Segment: 00:00:16.8800000 ==> 00:00:19.6400000 : 遇见你是我最幸福的事情New Segment: 00:00:19.6400000 ==> 00:00:22.3600000 : 你对我的好 我都记在心里New Segment: 00:00:22.3600000 ==> 00:00:25.1600000 : 真想不过一切奔向你的怀抱New Segment: 00:00:25.1600000 ==> 00:00:27.5200000 : 遇见你是我一生的幸运New Segment: 00:00:27.5200000 ==> 00:00:29.7600000 : 爱上你 是我一生的快乐New Segment: 00:00:29.7600000 ==> 00:00:32.3600000 : 失去你 是我一生的遗憾New Segment: 00:00:32.3600000 ==> 00:00:34.2000000 : 我们还能在一起吗New Segment: 00:00:34.2000000 ==> 00:00:35.8000000 : 早知道喜欢一个人New Segment: 00:00:35.8000000 ==> 00:00:38.1600000 : 会变得如此悲危和痛苦New Segment: 00:00:38.1600000 ==> 00:00:40.8800000 : 我宁愿我们从来没有相遇过New Segment: 00:00:40.8800000 ==> 00:00:42.1200000 : 曾经我以为New Segment: 00:00:42.1200000 ==> 00:00:45.1600000 : 需要有很多很多的人我才会欢乐New Segment: 00:00:45.1600000 ==> 00:00:46.5600000 : 直到遇到你以后New Segment: 00:00:46.5600000 ==> 00:00:48.0800000 : 我知道了只要你一人New Segment: 00:00:48.0800000 ==> 00:00:49.8400000 : 我边会很幸福New Segment: 00:00:49.8400000 ==> 00:00:52.3200000 : 只要你愿意 不管什么时候New Segment: 00:00:52.3200000 ==> 00:00:53.7600000 : 我都会在你身边New Segment: 00:00:53.7600000 ==> 00:00:55.3200000 : 因为我爱你New Segment: 00:00:55.3200000 ==> 00:00:57.1200000 : 想和你在一起New Segment: 00:00:57.1200000 ==> 00:00:59.1200000 : 我不在乎你的收入和地位New Segment: 00:00:59.1200000 ==> 00:01:01.1600000 : 我只想牵着你的手New Segment: 00:01:01.1600000 ==> 00:01:03.1600000 : 一起静静地走下去New Segment: 00:01:03.1600000 ==> 00:01:04.9600000 : 自从那次见了你之后New Segment: 00:01:04.9600000 ==> 00:01:06.6800000 : 你经常跑到我的梦里New Segment: 00:01:06.6800000 ==> 00:01:08.4800000 : 害得我心神不明New Segment: 00:01:08.4800000 ==> 00:01:10.9600000 : 这种感觉 你能理解吗New Segment: 00:01:10.9600000 ==> 00:01:12.7200000 : 有时候我真想忘了你New Segment: 00:01:12.7200000 ==> 00:01:14.1200000 : 只记得这个世界New Segment: 00:01:14.1200000 ==> 00:01:16.6800000 : 然而 我常常忘了整个世界New Segment: 00:01:16.6800000 ==> 00:01:18 : 只记得你New Segment: 00:01:18 ==> 00:01:19.4400000 : 当你难过的时候New Segment: 00:01:19.4400000 ==> 00:01:21.2400000 : 我希望能陪在你身边New Segment: 00:01:21.2400000 ==> 00:01:23.1600000 : 尽全力让你笑起来New Segment: 00:01:23.1600000 ==> 00:01:25.2400000 : 我不知道遇见你是对是错New Segment: 00:01:25.2400000 ==> 00:01:27.9200000 : 但我知道遇见你我开心过New Segment: 00:01:27.9200000 ==> 00:01:29.1200000 : 这么多年来New Segment: 00:01:29.1200000 ==> 00:01:31.3600000 : 我一直在寻找理想的爱情New Segment: 00:01:31.3600000 ==> 00:01:33.2400000 : 但没有一个人能像你那样New Segment: 00:01:33.2400000 ==> 00:01:35.2400000 : 在最初的时刻打动了我New Segment: 00:01:35.2400000 ==> 00:01:37.4400000 : 而且越来越深沉的打动New Segment: 00:01:37.4400000 ==> 00:01:38.8400000 : 我喜欢你New Segment: 00:01:38.8400000 ==> 00:01:40.3200000 : 就算你脾气不好New Segment: 00:01:40.3200000 ==> 00:01:41.9200000 : 说话那么难听New Segment: 00:01:41.9200000 ==> 00:01:43.0400000 : 习惯那么差New Segment: 00:01:43.0400000 ==> 00:01:44.1200000 : 心那么多情New Segment: 00:01:44.1200000 ==> 00:01:45.4000000 : 对我那么冷淡New Segment: 00:01:45.4000000 ==> 00:01:46.5600000 : 不爱说情话New Segment: 00:01:46.5600000 ==> 00:01:48.2000000 : 我还是喜欢你New Segment: 00:01:48.2000000 ==> 00:01:49.9600000 : 我知道你很忙New Segment: 00:01:49.9600000 ==> 00:01:51.2000000 : 不知道为什么New Segment: 00:01:51.2000000 ==> 00:01:53.0800000 : 总想与你在一起New Segment: 00:01:53.0800000 ==> 00:01:54.5200000 : 喜欢你的笑容New Segment: 00:01:54.5200000 ==> 00:01:56.4000000 : 喜欢静静地看着你New Segment: 00:01:56.4000000 ==> 00:01:58.0800000 : 忽然想不管不顾了New Segment: 00:01:58.0800000 ==> 00:01:59 : 什么是对New Segment: 00:01:59 ==> 00:02:00.0400000 : 什么是错New Segment: 00:02:00.0400000 ==> 00:02:01.5200000 : 只要能和你在一起New Segment: 00:02:01.5200000 ==> 00:02:03.4000000 : 一切都变得不重要New Segment: 00:02:03.4000000 ==> 00:02:04.5600000 : 我要你知道New Segment: 00:02:04.5600000 ==> 00:02:07.4800000 : 这个世界上有一个人会永远等着你New Segment: 00:02:07.4800000 ==> 00:02:09 : 无论是在什么时候New Segment: 00:02:09 ==> 00:02:10.8000000 : 无论你在什么地方New Segment: 00:02:10.8000000 ==> 00:02:12.9200000 : 你知道那个人是谁吗New Segment: 00:02:12.9200000 ==> 00:02:13.8400000 : 有些话New Segment: 00:02:13.8400000 ==> 00:02:15.8000000 : 我只对最喜欢的人诉说New Segment: 00:02:15.8000000 ==> 00:02:17.6800000 : 而你却常常听见New Segment: 00:02:17.6800000 ==> 00:02:18.8800000 : 在我的心底New Segment: 00:02:18.8800000 ==> 00:02:20.5200000 : 这世界上有一个New Segment: 00:02:20.5200000 ==> 00:02:22.1200000 : 对我最重要的名字New Segment: 00:02:22.1200000 ==> 00:02:24.5200000 : 那个人的名字与你重复New Segment: 00:02:24.5200000 ==> 00:02:25.8000000 : 我终于发现New Segment: 00:02:25.8000000 ==> 00:02:27.5200000 : 这世界上有丰厚的爱New Segment: 00:02:27.5200000 ==> 00:02:28.9600000 : 我不能辜负New Segment: 00:02:28.9600000 ==> 00:02:30.4000000 : 于是我想对你说New Segment: 00:02:30.4000000 ==> 00:02:31.2800000 : 我爱你New Segment: 00:02:31.2800000 ==> 00:02:32.4000000 : 请你轻听New Segment: 00:02:32.4000000 ==> 00:02:33.2400000 : 我的爱New Segment: 00:02:33.2400000 ==> 00:02:34.8800000 : 但生在很久很久New Segment: 00:02:34.8800000 ==> 00:02:36.7200000 : 那个见到你的从前New Segment: 00:02:36.7200000 ==> 00:02:37.8400000 : 只比为情New Segment: 00:02:37.8400000 ==> 00:02:38.8000000 : 落指邪你New Segment: 00:02:38.8000000 ==> 00:02:39.9600000 : 人生浮华New Segment: 00:02:39.9600000 ==> 00:02:41.0400000 : 岁月一托New Segment: 00:02:41.0400000 ==> 00:02:42 : 只你一念New Segment: 00:02:42 ==> 00:02:43.4400000 : 轻是永远New Segment: 00:02:43.4400000 ==> 00:02:44.9200000 : 可以清楚地回忆起New Segment: 00:02:44.9200000 ==> 00:02:46.8000000 : 和你在一起的每一个动作New Segment: 00:02:46.8000000 ==> 00:02:48.0800000 : 每一个表情New Segment: 00:02:48.0800000 ==> 00:02:49.0800000 : 这些声音New Segment: 00:02:49.0800000 ==> 00:02:50.1600000 : 这些影响New Segment: 00:02:50.1600000 ==> 00:02:52.3600000 : 都已经写进我的生命中New Segment: 00:02:52.3600000 ==> 00:02:53.5600000 : 我不小心把我爱你New Segment: 00:02:53.5600000 ==> 00:02:54.9600000 : 误发给你了New Segment: 00:02:54.9600000 ==> 00:02:57.1200000 : 如果你接受那就处存起来New Segment: 00:02:57.1200000 ==> 00:02:58.4400000 : 如果你不接受New Segment: 00:02:58.4400000 ==> 00:03:00.6400000 : 就把这三个字反发给我New Segment: 00:03:00.6400000 ==> 00:03:02.2000000 : 如果有一天New Segment: 00:03:02.2000000 ==> 00:03:03.7600000 : 我懂了爱情New Segment: 00:03:03.7600000 ==> 00:03:05.3200000 : 一定是因为你New Segment: 00:03:05.3200000 ==> 00:03:07.5600000 : 有一种想见不敢见的伤痛New Segment: 00:03:07.5600000 ==> 00:03:08.6400000 : 这一种喜欢New Segment: 00:03:08.6400000 ==> 00:03:10.1600000 : 还埋藏在我心中New Segment: 00:03:10.1600000 ==> 00:03:12.0800000 : 让我对你的怀念越来越浓New Segment: 00:03:12.0800000 ==> 00:03:14.5600000 : 我却只能把你你放在我心中New Segment: 00:03:14.5600000 ==> 00:03:17.1200000 : 有很多很多的话想对你说New Segment: 00:03:17.1200000 ==> 00:03:19 : 有很多很多的无能为力New Segment: 00:03:19 ==> 00:03:20.6400000 : 想请你来协助处理New Segment: 00:03:20.6400000 ==> 00:03:22.3200000 : 但最终一句话New Segment: 00:03:22.3200000 ==> 00:03:24.2000000 : 想你的觉得真好New Segment: 00:03:24.2000000 ==> 00:03:25.6000000 : 我喜欢你New Segment: 00:03:25.6000000 ==> 00:03:27.1200000 : 就算你脾气不好New Segment: 00:03:27.1200000 ==> 00:03:28.4400000 : 说话那么难听New Segment: 00:03:28.4400000 ==> 00:03:29.6000000 : 习惯那么差New Segment: 00:03:29.6000000 ==> 00:03:30.7200000 : 心那么多情New Segment: 00:03:30.7200000 ==> 00:03:31.8800000 : 对我那么冷淡New Segment: 00:03:31.8800000 ==> 00:03:33.9600000 : 我还是做不到不喜欢你New Segment: 00:03:33.9600000 ==> 00:03:35.0800000 : 对我来说New Segment: 00:03:35.0800000 ==> 00:03:37.8400000 : 你的名字跟我爱你是同一个意思New Segment: 00:03:37.8400000 ==> 00:03:39.6400000 : 在我说你名字的时候New Segment: 00:03:39.6400000 ==> 00:03:41.3600000 : 总会有我爱你这三个字New Segment: 00:03:41.3600000 ==> 00:03:43.1600000 : 无声的助解飘出New Segment: 00:03:43.1600000 ==> 00:03:44.6000000 : 自从你出现后New Segment: 00:03:44.6000000 ==> 00:03:47.1200000 : 我才知道原来暗恋的滋味那么苦New Segment: 00:03:47.1200000 ==> 00:03:48.8400000 : 这辈子最疯狂的事New Segment: 00:03:48.8400000 ==> 00:03:49.9600000 : 就是爱上了你New Segment: 00:03:49.9600000 ==> 00:03:51.1200000 : 最大的希望New Segment: 00:03:51.1200000 ==> 00:03:53.2800000 : 就是由你陪我疯一辈子New Segment: 00:03:53.2800000 ==> 00:03:55.6400000 : 闭上眼以为我能忘记你New Segment: 00:03:55.6400000 ==> 00:03:58.6400000 : 但留下的眼泪却没有骗到自己New Segment: 00:03:58.6400000 ==> 00:04:00.2400000 : 为什么婚那么喜欢你New Segment: 00:04:00.2400000 ==> 00:04:01.1600000 : 你惨了New Segment: 00:04:01.1600000 ==> 00:04:03.4800000 : 我为了喜欢你都没有时间表白了New Segment: 00:04:03.4800000 ==> 00:04:04.5600000 : 为了补偿我New Segment: 00:04:04.5600000 ==> 00:04:06.2800000 : 你必须对我说你爱我New Segment: 00:04:06.2800000 ==> 00:04:09.9200000 : 不然我一定会疼出时间向你表白的New Segment: 00:04:09.9200000 ==> 00:04:12.6000000 : 每天都是思念你度过New Segment: 00:04:12.6000000 ==> 00:04:14.8400000 : 想到你总会有开心的感觉New Segment: 00:04:14.8400000 ==> 00:04:16.3200000 : 从心底蔓延New Segment: 00:04:16.3200000 ==> 00:04:18.5600000 : 每天的功课都是想你New Segment: 00:04:18.5600000 ==> 00:04:19.3600000 : 想你New Segment: 00:04:19.3600000 ==> 00:04:20.4000000 : 想你New Segment: 00:04:20.4000000 ==> 00:04:21.4400000 : 我幻想过New Segment: 00:04:21.4400000 ==> 00:04:23.3200000 : 我们在一起是怎样的New Segment: 00:04:23.3200000 ==> 00:04:24.4400000 : 你会宠着我New Segment: 00:04:24.4400000 ==> 00:04:25.2800000 : 爱着我New Segment: 00:04:25.2800000 ==> 00:04:26.5200000 : 在乎我New Segment: 00:04:26.5200000 ==> 00:04:27.7200000 : 我也会顺着你New Segment: 00:04:27.7200000 ==> 00:04:28.6800000 : 体贴你New Segment: 00:04:28.6800000 ==> 00:04:29.8800000 : 关心你New Segment: 00:04:29.8800000 ==> 00:04:31.8000000 : 认识你的第一天New Segment: 00:04:31.8000000 ==> 00:04:33.8000000 : 我就被你的眼神所征服New Segment: 00:04:33.8000000 ==> 00:04:35.2800000 : 那时候我也知道New Segment: 00:04:35.2800000 ==> 00:04:36.4400000 : 如果你愿意New Segment: 00:04:36.4400000 ==> 00:04:38.5200000 : 我将是你一生的服务New Segment: 00:04:38.5200000 ==> 00:04:40.0400000 : 想听到你的声音New Segment: 00:04:40.0400000 ==> 00:04:41.8800000 : 记下你说过的美句话New Segment: 00:04:41.8800000 ==> 00:04:43.6000000 : 想见到你熟悉的脸New Segment: 00:04:43.6000000 ==> 00:04:45.2000000 : 记下你的温暖微笑New Segment: 00:04:45.2000000 ==> 00:04:46.9200000 : 想知道你对我的感觉New Segment: 00:04:46.9200000 ==> 00:04:49.1600000 : 还有想问问看我可以喜欢你吗New Segment: 00:04:49.1600000 ==> 00:04:50.3200000 : 我不要先花New Segment: 00:04:50.3200000 ==> 00:04:51.1600000 : 不要掌声New Segment: 00:04:51.1600000 ==> 00:04:52.9600000 : 我只想让你温暖的怀抱New Segment: 00:04:52.9600000 ==> 00:04:54.2400000 : 给我一个机会New Segment: 00:04:54.2400000 ==> 00:04:55.6800000 : 让我住进你的心里New Segment: 00:04:55.6800000 ==> 00:04:57.1600000 : 听你心跳的声音New Segment: 00:04:57.1600000 ==> 00:04:58.0800000 : 好不好

附录-微软xiaoxiao朗读的文本:

曾经我以为,这一辈子我都不会再遇到喜欢的人。直到遇见你,那种心动的感觉,我想控制,想忘记,却无能为力。与你相处的时间越久,对你的喜欢就越深,感觉就越强烈,你会不会跟我一样?遇见你,是我最幸福的事情。你对我的好,我都记在心里。真想不顾一切,奔向你的怀抱……遇见你,是我一生的幸运;爱上你,是我一生的快乐;失去你,是我一生的遗憾。我们还能在一起吗?早知道喜欢一个人,会变得如此卑微和痛苦,我宁愿我们从来没有相遇过。曾经我以为,需要有很多很多的人我才会欢乐,直到遇到你以后,我知道了只要你一人,我便会很幸福。只要你愿意,不管什么时候,我都会在你身边,因为我爱你,想和你在一起。我不在乎你的收入和地位,我只想,牵着你的手,一起静静地走下去。自从那次见了你之后,你经常跑到我的梦里,害得我心神不宁。这种感觉,你能理解吗?有时候我真想忘了你,只记得这个世界,然而,我常常忘了整个世界,只记得你。当你难过的时候,我希望能陪在你身边,尽全力让你笑起来。我不知道遇见你是对是错,但我知道遇见你我开心过。这么多年来,我一直在寻找理想的爱情,但没有一个人能像你那样,在最初的时刻打动了我,而且越来越深沉地打动。我喜欢你!就算你脾气不好,说话那么难听,习惯那么差,心那么多情,对我那么冷淡,不爱说情话,我还是喜欢你!我知道你很忙,不知道为什么,总想与你在一起!喜欢你的笑容,喜欢静静的看着你。忽然想不管不顾了,什么是对,什么是错,只要能和你在一起,一切都变得不重要!我要你知道,这个世界上有一个人会永远等着你。无论是在什么时候,无论你在什么地方。你知道那个人是谁吗?有些话,我只对最喜欢的人诉说,而你却常常听见。在我的心底,这世界上有一个对我最重要的名字,那个人的名字与你重复。我终于发现,这世界上有丰厚的爱,我不能辜负。于是我想对你说,我爱你,请你倾听……我的爱,诞生在很久很久,那个见到你的从前。执笔为情,落纸写你,人生浮华,岁月依托,执你一念,倾世永远。可以清楚的回忆起和你在一起的每一个动作、每一个表情,这些声音、这些影像,都已经写进我的生命中。我不小心把"我爱你"误发给你了。如果你接受那就储存起来,如果你不接受,就把这三个字返发给我。如果有一天。我懂了爱情。一定是因为你。有一种想见不敢见的伤痛,这一种喜欢还埋藏在我心中,让我对你的怀念越来越浓,我却只能把你你放在我心中。有很多很多的话想对你说。有很多很多的无能为力想请你来协助处理,但最终一句话。想你的觉得真好!我喜欢你!就算你脾气不好,说话那么难听,习惯那么差,心那么多情,对我那么冷淡,我还是做不到不喜欢你!对我来说,你的名字跟我爱你是同一个意思,在我说你名字的时候,总会有我爱你这三个字无声的注解飘出。自从你出现后,我才知道原来暗恋的滋味那么苦……这辈子最疯狂的事,就是爱上了你,最大的希望,就是有你陪我疯一辈子.....闭上眼,以为我能忘记你,但流下的眼泪,却没有骗到自己。为什么会那么喜欢你……你惨啦!我为了喜欢你都没有时间表白了,为了补偿我,你必须对我说你爱我,不然,我一定会腾出时间向你表白的。每天,都是思念你度过。想到你,总会有开心的感觉从心底蔓延。每天的功课,都是想你、想你、想你。我幻想过我们在一起是怎样的。你会宠着我,爱着我,在乎我。我也会顺着你,体贴你,关心你。认识你的第一天,我就被你的眼神所征服,那时候我已知道,如果你愿意,我将是你一生的俘虏!想听到你的声音,记下你说过的每句话;想见到你熟悉的脸,记下你的温暖微笑,想知道你对我的感觉,还有想问问看我可以喜欢你吗" />The End