A duniyar fasaha, neman bayanai akan intanit ya zama wani muhimmin bangare na rayuwarmu ta yau da kullun. Tare da gidajen yanar gizo marasa adadi da ke ba da ilimi kan batutuwa masu tarin yawa, Wikipedia ษaya ce irin wannan dandali da ke aiki a matsayin babban kundin sani. Tambayar ta taso - ta yaya za mu iya bincika yadda ya kamata a kan Wikipedia kuma a bayyana sakamakon da babbar murya? A cikin wannan labarin, za mu bincika mafita ga wannan matsala, bayanin mataki-mataki na lambar Python, da zurfafa zurfin cikin ษakunan karatu da ayyukan da aka yi amfani da su.
Don magance wannan batu, za mu ฦirฦiri rubutun Python wanda zai ษauki tambayar bincike, za mu debo bayanan da suka dace daga Wikipedia, sannan mu karanta taฦaitaccen sakamakon. Za a cimma wannan ta amfani da dakunan karatu na Wikipedia da pyttsx3. Bari mu nutse cikin bayanin mataki-mataki na lambar.
Mataki na farko shine shigar da ษakunan karatu da ake buฦata, waษanda za'a iya yin su ta amfani da pip:
pip install wikipedia pip install pyttsx3
Wikipedia Library
The Laburaren Wikipedia Python wrapper ne don API na Wikipedia. Yana ba mu damar cirewa bayanai da taฦaitawa daga labaran Wikipedia, bincika labarai, har ma da fassara labarai. A cikin rubutun mu, za mu yi amfani da wikipedia.search() da wikipedia.summary() ayyuka don nemo batun da ake so da kuma kawo taฦaicensa.
Pyttsx3 Library
The pyttsx3 library (gajeren sigar Python Text-to-Speech 3) ษakin karatu ne wanda ke ba da damar aikin rubutu-zuwa-magana a Python. Yana da dandamali-mai zaman kansa kuma yana aiki tare da Windows da macOS. Wannan ษakin karatu baya buฦatar haษin Intanet kuma yana dacewa da Python 2 da Python 3. A cikin rubutun mu, za mu yi amfani da pyttsx3.init() da pyttsx3.say() ayyuka don fara injin rubutu-zuwa-magana da magana taฦaice daga Wikipedia.
Bayanin Code
Tare da shigar da ษakunan karatu da ake buฦata, yanzu za mu iya ci gaba da rubuta rubutun mu na Python:
import wikipedia import pyttsx3 # Initialize the text-to-speech engine engine = pyttsx3.init() # Take the search query as input and search on Wikipedia query = input("Enter the topic to search on Wikipedia: ") results = wikipedia.search(query) # Print the search results print("Search results:") for result in results: print(result) # Choose the desired result, fetch the summary, and speak it choice = input("Enter the name of the article you want to get the summary for: ") summary = wikipedia.summary(choice) engine.say(summary) engine.runAndWait()
A cikin rubutun, mun fara shigo da dakunan karatu da ake buฦata (wikipedia da pyttsx3) kuma mu fara injin rubutu-zuwa-magana. Sai mu tambayi mai amfani tambayar tambayar su, yi amfani da wikipedia.search() aiki don bincika batun akan Wikipedia, da nuna sakamakon. Mai amfani zai iya zaษar sakamakon da ake so, kuma mun kawo taฦaitawar ta amfani da wikipedia.summary() aiki. A ฦarshe, muna amfani da pyttsx3.ce() da kuma pyttsx3.runAndWait() ayyuka don yin magana taฦaice.
Tare da wannan rubutun, yanzu zaku iya nemo kowane batu akan Wikipedia kuma ku sami taฦaitaccen bayanin da babbar murya ta amfani da shi Python, ษakin karatu na Wikipedia, da pyttsx3. Neman farin ciki!