今天我要和大家分享一個新功能更新——微軟的文本轉(zhuǎn)語音和語音轉(zhuǎn)文本功能。最近,微軟對其AI語音識別和語音合成技術進行了重大升級,效果非常好,現(xiàn)在我將分別為大家介紹這兩個功能。
先來聽下這個效果吧
微軟文本轉(zhuǎn)語音和語音轉(zhuǎn)文本功能更新
文本轉(zhuǎn)語音
文本轉(zhuǎn)語音(Text-to-Speech, TTS)是一種將文本信息轉(zhuǎn)換為自然聽起來的語音的技術。微軟的文本轉(zhuǎn)語音功能提供了多種語言和語音選項,支持多種平臺和設備,使得用戶可以輕松將文本轉(zhuǎn)換為語音。
更新后的文本轉(zhuǎn)語音功能在語音合成方面有了很大的提升。它不僅能夠更自然地模擬人類語音的語調(diào)、語速和語調(diào)變化,還能夠根據(jù)上下文智能調(diào)整發(fā)音,使得合成的語音更加自然流暢。
python代碼如下:運行后,會在終端運行的目錄下生成一個output.mp3文件
from azure.cognitiveservices.speech import SpeechConfig, SpeechSynthesizer, AudioConfig
from azure.cognitiveservices.speech.audio import AudioOutputConfig
from azure.cognitiveservices.speech import ResultReason, CancellationReason
# 創(chuàng)建SpeechConfig對象
speech_config = SpeechConfig(subscription="key", region="service_region")
# 創(chuàng)建音頻配置對象
audio_config = AudioConfig(filename="output.mp3") # 輸出到MP3文件
# 創(chuàng)建語音合成器
speech_synthesizer = SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
text="How To Unlock Cyberpunk 2077’s New Ending In Phantom Liberty"
# 定義SSML文本
ssml_string2="""
<!--ID=B7267351-473F-409D-9765-754A8EBCDE05;Version=1|{"VoiceNameToIdMapItems":[{"Id":"390baec9-d867-4c01-bdcf-04e5848ee7dc","Name":"Microsoft Server Speech Text to Speech Voice (zh-CN, XiaoxiaoMultilingualNeural)","ShortName":"zh-CN-XiaoxiaoMultilingualNeural","Locale":"zh-CN","VoiceType":"StandardVoice"}]}-->
<!--ID=FCB40C2B-1F9F-4C26-B1A1-CF8E67BE07D1;Version=1|{"Files":{}}-->
<!--ID=5B95B1CC-2C7B-494F-B746-CF22A0E779B7;Version=1|{"Locales":{"zh-CN":{"AutoApplyCustomLexiconFiles":[{}]},"de-DE":{"AutoApplyCustomLexiconFiles":[{}]}}}-->
<speak xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts" xmlns:emo="http://www.w3.org/2009/10/emotionml" version="1.0" xml:lang="zh-CN"><voice name="zh-CN-XiaoxiaoMultilingualNeural"><lang xml:lang="zh-CN"><s />但我現(xiàn)在對這個職業(yè)的熱愛還是非常的,呵呵,非常的,嗯,怎么說呢?日月可鑒的,哈哈,嗯還是希望可以把這個職業(yè)做下去或者做這個聲音相關領域的工作,嗯,就是把自己的優(yōu)勢發(fā)揮的大一點,盡可能能用到自己擅長的東西,而不是說為了工作,為了掙錢而工作。<s /></lang></voice></speak>
"""
# 使用SSML文本進行語音合成
result = speech_synthesizer.speak_ssml_async(ssml_string2).get()
# 檢查結果
if result.reason == ResultReason.SynthesizingAudioCompleted:
print("Speech synthesized to [output.mp3] for text [{}]".format(ssml_string2))
elif result.reason == ResultReason.Canceled:
cancellation_details = result.cancellation_details
print("Speech synthesis canceled: {}".format(cancellation_details.reason))
if cancellation_details.reason == CancellationReason.Error:
if cancellation_details.error_details:
print("Error details: {}".format(cancellation_details.error_details))
print("Did you update the subscription info?")
其中,Service_region和key值需要到azure中去獲取,先選語音服務
語音轉(zhuǎn)文本
語音轉(zhuǎn)文本(Speech-to-Text, STT)則是一種將語音信息轉(zhuǎn)換為文本的技術。微軟的語音轉(zhuǎn)文本功能支持多種語言和方言,能夠?qū)崟r將語音轉(zhuǎn)換為文本,并提供了強大的噪聲抑制和回聲消除功能,使得識別準確率大大提高。
python代碼如下:
import os
import tkinter as tk
from tkinter import filedialog, ttk
import azure.cognitiveservices.speech as speechsdk
from datetime import datetime
# 配置Azure語音服務的密鑰和區(qū)域
speech_key = "key"
service_region = "service_region"
def recognize_speech():
# 獲取選擇的WAV文件路徑
wav_file = filedialog.askopenfilename(filetypes=[("WAV Files", "*.wav")])
if wav_file:
# 更新狀態(tài)標簽
status_label.config(text="正在識別...")
# 創(chuàng)建語音配置對象,并設置語言為中文
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
speech_config.speech_recognition_language = "zh-CN"
# 創(chuàng)建音頻配置對象
audio_config = speechsdk.audio.AudioConfig(filename=wav_file)
# 創(chuàng)建語音識別器對象
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)
# 定義識別結果的回調(diào)函數(shù)
recognized_text = []
def handle_final_result(evt):
recognized_text.append(evt.result.text)
progress_bar.step(10) # 每次識別結果更新進度條
# 連接識別結果的事件處理程序
speech_recognizer.recognized.connect(handle_final_result)
# 定義識別狀態(tài)的標志變量
is_recognizing = True
# 定義識別結束的回調(diào)函數(shù)
def handle_session_stopped(evt):
nonlocal is_recognizing
is_recognizing = False
# 連接識別結束的事件處理程序
speech_recognizer.session_stopped.connect(handle_session_stopped)
# 執(zhí)行連續(xù)識別
speech_recognizer.start_continuous_recognition()
# 等待連續(xù)識別完成
while is_recognizing:
window.update()
# 停止連續(xù)識別
speech_recognizer.stop_continuous_recognition()
# 獲取當前時間戳
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
# 構建保存文件的路徑
save_path = os.path.join("C:\\temp", f"recognized_text_{timestamp}.txt")
# 將識別結果保存到文件
with open(save_path, "w", encoding="utf-8") as file:
file.write("\n".join(recognized_text))
# 更新狀態(tài)標簽
status_label.config(text="識別完成,結果已保存到文件: " + save_path)
# 重置進度條
progress_bar["value"] = 0
# 創(chuàng)建圖形化界面
window = tk.Tk()
window.title("語音識別")
# 創(chuàng)建選擇文件按鈕
select_button = tk.Button(window, text="選擇WAV文件", command=recognize_speech)
select_button.pack(pady=10)
# 創(chuàng)建狀態(tài)標簽
status_label = tk.Label(window, text="請選擇要識別的WAV文件")
status_label.pack()
# 創(chuàng)建進度條
progress_bar = ttk.Progressbar(window, length=200, mode="determinate")
progress_bar.pack(pady=10)
# 運行圖形化界面
window.mainloop()
運行后,效果如下:
總結
總的來說,微軟的文本轉(zhuǎn)語音和語音轉(zhuǎn)文本功能的這次更新,無疑是一次重大的技術突破。它不僅為用戶提供了更加自然流暢的語音合成體驗,還極大地提高了語音識別的準確率。這對于需要使用語音識別和語音合成功能的用戶來說,無疑是一個巨大的福音。文章來源:http://www.zghlxwxcb.cn/news/detail-849185.html
好了,今天的分享就到這里。如果你對這兩個功能有更多的疑問或者想法,歡迎在評論區(qū)留言討論。我們下期再見!文章來源地址http://www.zghlxwxcb.cn/news/detail-849185.html
到了這里,關于微軟文本轉(zhuǎn)語音和語音轉(zhuǎn)文本功能更新,效果顯著!的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!